From da632baf34ef2308da04c56c497e115b9d1ad531 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sat, 23 Oct 2021 00:24:51 +0200 Subject: QTabBar: re-layout when tab size hint depends on selected state QTabBar caches the rects for the tabs to avoid costly recalculation of each tab's size hint. That cache is only updated via layoutTabs if the entire tab bar is resized or modified. However, when a style sheet is set that calculates a different size hint for tabs that are selected, then the tab bar also needs to be laid-out when the current tab changes. To minimize the cost, compare the cached size for the new current tab with its new size hint, and re-layout the tabs when they are different. Fixes: QTBUG-6905 Fixes: QTBUG-8209 Pick-to: 6.2 Change-Id: I110444d18938c2b3446ee58e4a8c6c472b5f12c3 Reviewed-by: Shawn Rutledge --- src/widgets/widgets/qtabbar.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 11fa33ca15..8fd5bbfb56 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -1433,6 +1433,13 @@ void QTabBar::setCurrentIndex(int index) int oldIndex = d->currentIndex; if (auto tab = d->at(index)) { d->currentIndex = index; + // If the size hint depends on whether the tab is selected (for instance a style + // sheet rule that sets a bold font on the 'selected' tab) then we need to + // re-layout the entire tab bar. To minimize the cost, do that only if the + // size hint changes for the tab that becomes the current tab (the old curent tab + // will most certainly do the same). QTBUG-6905 + if (tabRect(index).size() != tabSizeHint(index)) + d->layoutTabs(); update(); d->makeVisible(index); if (d->validIndex(oldIndex)) { -- cgit v1.2.3