Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Calculating the exact needed height for a QTableWidget



  • Hi :-)

    I want to calculate the exact height a QTableWidget needs so that no vertical scroll bar is shown. What I do right now is for example:

    tableWidget->setMaximumHeight(tableWidget->horizontalHeader()->height()
                                  + tableWidget->rowHeight(0) * 4
                                  + 4);
    

    for this case, having 4 rows and KDE's Breeze style set, this works exactly:

    breeze.png

    But the additional 4 pixels seem to be style-dependent, using the Fusion style I get a bit more space than I need (cf. the last row, there are 2 unneeded white pixels):

    fusion.png

    Is there a way to calculate the exact size independently of the style? I did not find anything fitting yet …

    Thanks for all help!


Log in to reply