Note that there are some explanatory texts on larger screens.

plurals
  1. POQt widget size recalculation at runtime
    primarykey
    data
    text
    <p>I have a problem with size calculation in Qt when adding new widgets at run time. I have tried to illustrate the problem with the pruned program down there. Hopefully, it shows the same problem than my other (more complex) program:</p> <p>When a widget has been shown, using:</p> <pre><code>w-&gt;show(); </code></pre> <p>...and some new widgets are added to it later on (possibly <code>w</code> has a layout), what should I do to redisplay <code>w</code> and its parents so that the size of the newly added child widgets is taken into account? The behaviour I want is that the size recalculation propagates upward to the nearest scrolled object (or the main window if there is no scrolled objects)</p> <p>In the example below, I create a little widget structure: if the call to <code>show()</code> (commented SHOW1) is removed, then the whole widget structure is defined before the first call to <code>show()</code> and everything works. BUT: if I do call <code>show()</code> (at SHOW1), then the last show does not display the right things: the frame is still too small</p> <pre><code> #include &lt;QApplication&gt; #include &lt;QtCore&gt; #include &lt;QMainWindow&gt; #include &lt;QTabWidget&gt; #include &lt;QWidget&gt; #include &lt;QGroupBox&gt; #include &lt;QVBoxLayout&gt; #include &lt;QLabel&gt; #include &lt;stdlib.h&gt; int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow* main_window = new(QMainWindow); main_window-&gt;setObjectName("main_window"); main_window-&gt;resize(800, 600); main_window-&gt;setWindowTitle("Hello"); QTabWidget* node_tab_widget = new QTabWidget(main_window); node_tab_widget-&gt;setObjectName(QString::fromUtf8("tab_widget")); QWidget* w= new QWidget(node_tab_widget); node_tab_widget-&gt;addTab(w, "TAB"); QGroupBox* group_widget = new QGroupBox("GROUPNAME", w); QVBoxLayout* group_layout = new QVBoxLayout; group_widget-&gt;setLayout(group_layout); group_layout-&gt;addWidget((QLabel*)new QLabel("&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;here1")); main_window-&gt;show(); // SHOW1: If this one is commented, then OK! group_layout-&gt;addWidget((QLabel*)new QLabel("here2")); group_layout-&gt;addWidget((QLabel*)new QLabel("here2")); group_layout-&gt;addWidget((QLabel*)new QLabel("here2")); group_layout-&gt;addWidget((QLabel*)new QLabel("here2")); main_window-&gt;setCentralWidget(node_tab_widget); // main_window-&gt;update(); // main_window-&gt;hide(); main_window-&gt;show(); // How to I get that to recaclulate the size of its contents? return app.exec(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload