Important: Please read the Qt Code of Conduct -

QTableView width and columns width

  • Hi! I have a QTableView placed into a horizontal layout in a QMainWindow. When the table is empty (I mean no model is set yet) the user can resize the main window (and therefore the table) down to a very small size.
    After setting the model, two odd things happen:

    1. the QMainWindow resize itself to accomodate the columns
    2. the user cannot shrink the window below the whole width of the column.

    Both behaviors are unwanted in my application. I need to maintain the current window's size and let the user to change its dimensions how he likes. Of course if the width of the table is less than the whole width of the columns I expect to use scrollbars.

    Which property you recommend to look for?

  • Lifetime Qt Champion


    You can try and modify the QSizePolicy of your QTableView

  • @SGaist
    The QSizePolicy is set to Expanding, because I want the table should take all the space by default. Anyway I tried to set it to Minimum but nothing changes. It seems something force the minimum size of the table, but I printed out the actual minimumSize value and is set to 0, even after adding the contents.