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



  • To expand to fill the white space

    tablewidget->horizontalHeader()->setStretchLastSection(true);
    tablewidget->verticalHeader()->setStretchLastSection(true);
    

    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);
    


  • @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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.