Fixed optimal size of QTableView when rows and columns count never change



  • I'm developing an editor for a a piece of hardware and presenting some parameters as two QTableView. The rows and columns count never change for each table, but one table has 4 columns, the other 3.

    These table should never be resized when the window is resized: another widget will grow (a list a presets), as a space below the tables. The width of the right section of the UI should be driven by the top QTableView (the one with 4 columns).

    Here is what I have now:
    Now

    And this what I'd like to obtain:
    Want

    1. How can I specify that the QTableView geometries should never change after being optimally sized ?

    2. Is there a way to tell the bottom QTableView (the one with 3 columns) to equally size the columns to fill the available space ?

    Many thanks !



  • @charlesfleche said in Fixed optimal size of QTableView when rows and columns count never change:

    How can I specify that the QTableView geometries should never change after being optimally sized ?

    tableView->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
    tableView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
    

    @charlesfleche said in Fixed optimal size of QTableView when rows and columns count never change:

    Is there a way to tell the bottom QTableView (the one with 3 columns) to equally size the columns to fill the available space ?

    tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);

    You can do all the above even in desinger.
    You'll have to put a QSpacerItem below the second table



  • @VRonin Pefect ! I had to fight a bit with the spacer on the Midi channel row, but apart from that, you were spot on. Many thanks !


Log in to reply