Important: Please read the Qt Code of Conduct -

How to set ResizetoContent for a single column in TableWidget?

  • Hello,

    I am new to Qt and I am using PyQt 5.8.

    I had my columns set to resizeColumnsToContents() but when setting setStretchLastSection(True), the table is always resizing to fit the content, even though I am manually setting the setStretchLastSection(True) once more.

    Is there anything I can do to prevent it from doing so? I thought about setting 6 of my 7 columns to resizetoContent, so the StretchLastSection won't be overwritten, but I can't seem to find a way to do so.

    (setStretchLastSection(True) is also set to true through Qt-Designer)

    my table is called table_1. my current code is below:


    thanks, I am open for constructive critics.

  • What Qt version are you using?

  • Oups, Qt 5.8

  • lets you set the resize mode for each column


    my columns set to resizeColumnsToContents() but when setting setStretchLastSection(True)


    verticalHeader is for the rows, horizontalHeader is for the columns

Log in to reply