QToolButton: properly reset the size hint when a menu is set on it
QToolButton::sizeHint() takes into account the presence of a menu. However, setMenu() doesn't retrigger a size hint recalculation. Hence, (un)setting a menu on an already sized tool button won't properly reset the size hint. Since the calculated size hint is cached, delete the cached value and call updateGeometry to cause a recalculation. Task-number: QTBUG-38949 Change-Id: I6e79e5e70e31afdfd129282b3668875eca86f51d Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
055622ed48
commit
bb3d2ca9f1
@ -652,6 +652,10 @@ void QToolButton::setMenu(QMenu* menu)
|
||||
} else {
|
||||
d->menuAction = 0;
|
||||
}
|
||||
|
||||
// changing the menu set may change the size hint, so reset it
|
||||
d->sizeHint = QSize();
|
||||
updateGeometry();
|
||||
update();
|
||||
}
|
||||
|
||||
|
@ -66,6 +66,7 @@ private slots:
|
||||
void task230994_iconSize();
|
||||
void task176137_autoRepeatOfAction();
|
||||
void qtbug_26956_popupTimerDone();
|
||||
void qtbug_34759_sizeHintResetWhenSettingMenu();
|
||||
|
||||
protected slots:
|
||||
void sendMouseClick();
|
||||
@ -265,5 +266,32 @@ void tst_QToolButton::qtbug_26956_popupTimerDone()
|
||||
tb->showMenu();
|
||||
}
|
||||
|
||||
void tst_QToolButton::qtbug_34759_sizeHintResetWhenSettingMenu()
|
||||
{
|
||||
// There is no reliable way of checking what's ultimately a style-dependent
|
||||
// sizing. So the idea is checking if the size is the "correct" size w.r.t.
|
||||
// another toolbutton which has had a menu set before it was shown for the first time
|
||||
|
||||
QToolButton button1;
|
||||
QToolButton button2;
|
||||
|
||||
button1.setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
button1.setPopupMode(QToolButton::MenuButtonPopup);
|
||||
|
||||
button2.setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
button2.setPopupMode(QToolButton::MenuButtonPopup);
|
||||
|
||||
button2.setMenu(new QMenu(&button2));
|
||||
|
||||
button1.show();
|
||||
button2.show();
|
||||
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&button1));
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&button2));
|
||||
|
||||
button1.setMenu(new QMenu(&button1));
|
||||
QTRY_COMPARE(button1.sizeHint(), button2.sizeHint());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QToolButton)
|
||||
#include "tst_qtoolbutton.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user