Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt QHeaderView::sectionResized and QHeaderView::geometriesChanged not working as expected

Tags:

c++

qt

I'm using Qt 5.7, and I have a QWidgetTable that starts off with no rows. When I insert the first row, the width of the table's verticalHeader (which has type QHeaderView) changes from 0 to 15. Yet neither signal is fired.

Perhaps sectionResized means that the user has resized the section with the mouse, but shouldn't geometriesChanged definitely be fired?

I need this because I want the QWidgetTable to resize its width correctly to the contents. But if I call the resize function manually immediately after inserting or deleting a row, the width() member function of the verticalHeader returns the old value. For example, it returns 0 immediately after inserting the first row even though it should be 15.

like image 565
James Hirschorn Avatar asked Sep 07 '25 22:09

James Hirschorn


1 Answers

Looking at Qt source code, geometriesChanged only fired in these cases:

case QEvent::FontChange:
case QEvent::StyleChange:
        d->invalidateCachedSizeHint();
        Q_FALLTHROUGH();
case QEvent::Hide:
case QEvent::Show: {
        ....
            resizeSections();
        emit geometriesChanged();
        break;}
like image 55
m. c. Avatar answered Sep 09 '25 13:09

m. c.