开发者

Why can I only add elements to a QWidget during runtime if the QWidget isn't visible on the screen?

开发者 https://www.devze.com 2023-03-20 04:47 出处:网络
I have a strange problem when trying to add buttons to a QWidget during run-time. I have a window with a QTabWidget, and it has 2 tabs. When I press a button on the window it generates an array of che

I have a strange problem when trying to add buttons to a QWidget during run-time. I have a window with a QTabWidget, and it has 2 tabs. When I press a button on the window it generates an array of check boxes on the first tab.

The problem is, when I have the first tab open, nothing happens when开发者_如何学JAVA I press the button, but if I open the second tab, press the button, then return to the first tab, the check boxes appear properly. This is a sample from the code that creates the check boxes:

for(int i = 0; i < x_dim; ++i){
    for(int j = 0; j < y_dim; ++j){
        checkBoxVector.append(new QCheckBox( ui->dim1 ));
        checkBoxVector.last()->setGeometry(i * 20, j * 20, 20, 20);
    }
}

Is there some sort of property I have to enable in the QTabWidget for this to work as it should?


You probably need to show() the newly created widget and let the layout update:

checkBoxVector.last()->show();
ui->dim1->updateGeometry();
0

精彩评论

暂无评论...
验证码 换一张
取 消