Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understood your question, you want the two QTableViews to resize to their PreferredSize if there is enough space (but no more than thier PreferredSize) and to shrink if there is not enough space. If there is too much space, it should be left empty. Here's an example that does it:</p> <pre><code>#include &lt;QtGui&gt; int main(int argc, char **argv) { QApplication app(argc, argv); QMainWindow w; QHBoxLayout *hbox = new QHBoxLayout; QWidget *centralw = new QWidget; centralw-&gt;setLayout(hbox); w.setCentralWidget(centralw); QTableView *t1 = new QTableView; QTableView *t2 = new QTableView; // Version one: the preferred size is the maximum size // t1-&gt;setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); // t2-&gt;setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred)); // Version two: the preferred size is the only accepted size // if you want the widgets not to change their size, change the two previous lines with // t1-&gt;setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); // t2-&gt;setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); // hbox-&gt;addWidget(t1); // hbox-&gt;addWidget(t2); // add a stretch that will fill empty space // hbox-&gt;addStretch(1); // Version three: tables have a minimum and maximum width. They can be shrunk // but they try to expand to take the maximum available space up to their maximum // width. t1-&gt;setMinimumWidth(150); t1-&gt;setMaximumWidth(400); t2-&gt;setMinimumWidth(100); t2-&gt;setMaximumWidth(200); t1-&gt;setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); t2-&gt;setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding)); hbox-&gt;addWidget(t1); hbox-&gt;addWidget(t2); hbox-&gt;setStretchFactor(t1, 1); hbox-&gt;setStretchFactor(t2, 1); // tableviews have the same stretch factor hbox-&gt;addStretch(0); // lowest stretch factor w.show(); 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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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