From ed4066369adbc547a76d2fed08ec4950a5f9edf0 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 13 Jan 2021 17:50:16 +0100 Subject: [PATCH] better handling of finding the current item after removeing an item --- src/layouts/QskStackBox.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/layouts/QskStackBox.cpp b/src/layouts/QskStackBox.cpp index 3d85d709..7ee11a1a 100644 --- a/src/layouts/QskStackBox.cpp +++ b/src/layouts/QskStackBox.cpp @@ -269,8 +269,20 @@ void QskStackBox::removeItemInternal( int index, bool unparent ) m_data->items.removeAt( index ); - if ( index <= m_data->currentIndex ) - Q_EMIT currentIndexChanged( --m_data->currentIndex ); + auto& currentIndex = m_data->currentIndex; + + if ( index <= currentIndex ) + { + currentIndex--; + + if ( currentIndex < 0 && !m_data->items.isEmpty() ) + currentIndex = 0; + + if ( currentIndex >= 0 ) + m_data->items[ currentIndex ]->setVisible( true ); + + Q_EMIT currentIndexChanged( currentIndex ); + } resetImplicitSize(); polish();