Improve performance of QTabWidget::clear
The current implementation of QTabWidget::clear is quite poor because it deletes the tabs from first to last. When I was playing around, I found out it's much faster to delete from last to first (with a lot of tabs it goes from two seconds to 200 milliseconds in my testing). I assume this has to do with the redrawing of all remaining tabs for each removeTab call, while this is not necessary when removing in the reverse order. Also, disable the stack widget's layout while we remove all tabs to avoid unnecessary event posting, and disable updates of the stacked widget as well as the tab bar. Change-Id: I04972de05ab71f98da7f74412aaadc69a36efc32 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 8717c1752f9b72ac7c028b722f0a068e84e64eca) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
214101b1b3
commit
828ece4743
@ -1402,9 +1402,20 @@ void QTabWidget::setTabBarAutoHide(bool enabled)
|
||||
*/
|
||||
void QTabWidget::clear()
|
||||
{
|
||||
// ### optimize by introduce QStackedLayout::clear()
|
||||
while (count())
|
||||
removeTab(0);
|
||||
Q_D(QTabWidget);
|
||||
Q_ASSERT(d->stack->layout());
|
||||
d->stack->layout()->setEnabled(false);
|
||||
d->stack->setUpdatesEnabled(false);
|
||||
d->tabs->setUpdatesEnabled(false);
|
||||
|
||||
int c = count();
|
||||
while (c)
|
||||
removeTab(--c);
|
||||
|
||||
d->tabs->setUpdatesEnabled(true);
|
||||
d->stack->setUpdatesEnabled(true);
|
||||
d->stack->layout()->setEnabled(true);
|
||||
d->stack->layout()->activate();
|
||||
}
|
||||
|
||||
QTabBar::Shape _q_tb_tabBarShapeFrom(QTabWidget::TabShape shape, QTabWidget::TabPosition position)
|
||||
|
Loading…
x
Reference in New Issue
Block a user