From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.

How to remove white space around QTableWidget?

  • ![Good Day,
    Am trying to create a table with certain number of rows and columns, I am able to create a table perfectly fine, and this QTableWidget is been put in the mainwidget with some other visual elements, whenever i maximize the mainwidget i am getting this extra space around the table.
    How to get rid of that extra space please help!!0_1511486033601_Capture21234.PNG

  • Qt Champions 2018

    To expand to fill the white space


    To prevent expansion into whitespace (but might require you to set a maximum size manually) tablewidget->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents)

  • I am sorry sir, It is not working ,the last row is still stretched vertically :(

  • @Amogh Hi,friend. Welcome.

    Try below snippet again:

        QHeaderView* headerView = horizontalHeader();
        headerView->setSectionResizeMode(FirstColumn,         QHeaderView::Fixed);
        headerView->setSectionResizeMode(SecondColumn,    QHeaderView::ResizeToContents); 
        headerView->setSectionResizeMode(ThirdColumn,        QHeaderView::Stretch);

  • Qt Champions 2018

    @Amogh said in How to remove white space around QTableWidget?:

    the last row is still stretched vertically

    Yes, that's what tablewidget->verticalHeader()->setStretchLastSection(true); does. remove that line if that's not the behaviour you want

  • @VRonin @joeQ thanks a lot guys ...! really helped me figure it out !! :)

Log in to reply