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. Pick-to: 6.8 Change-Id: I04972de05ab71f98da7f74412aaadc69a36efc32 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
1393ece7c0
commit
8717c1752f
@ -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