From 1f899ebdbfb524b4ac5c4f3f472e2c48c8821d7e Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Mon, 15 May 2023 15:04:47 +0200 Subject: [PATCH] making QskMainView a focus scope, so that the focus does not get lost, when popups ( f.e menus ) have appeared --- src/controls/QskMainView.cpp | 21 +++++++++++++++++++++ src/controls/QskMainView.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/controls/QskMainView.cpp b/src/controls/QskMainView.cpp index 6b700eae..ddf55ec4 100644 --- a/src/controls/QskMainView.cpp +++ b/src/controls/QskMainView.cpp @@ -4,6 +4,7 @@ *****************************************************************************/ #include "QskMainView.h" +#include "QskQuick.h" /* This code is a placeholder implementation until we know @@ -24,6 +25,9 @@ QskMainView::QskMainView( QQuickItem* parent ) setAutoAddChildren( false ); setSpacing( 0 ); setPanel( true ); + + setFlag( QQuickItem::ItemIsFocusScope, true ); + setFocusPolicy( Qt::StrongFocus ); } QskMainView::~QskMainView() @@ -90,4 +94,21 @@ void QskMainView::setFooter( QskControl* footer ) } } +void QskMainView::focusInEvent( QFocusEvent* event ) +{ + Inherited::focusInEvent( event ); + + if ( isFocusScope() && ( scopedFocusItem() == nullptr ) ) + { + if ( auto focusItem = nextItemInFocusChain( true ) ) + { + if ( qskIsItemComplete( focusItem ) + && qskIsAncestorOf( this, focusItem ) ) + { + focusItem->setFocus( true ); + } + } + } +} + #include "moc_QskMainView.cpp" diff --git a/src/controls/QskMainView.h b/src/controls/QskMainView.h index fa53f3bc..c0160e6c 100644 --- a/src/controls/QskMainView.h +++ b/src/controls/QskMainView.h @@ -27,6 +27,9 @@ class QSK_EXPORT QskMainView : public QskLinearBox QskControl* footer() const; void setFooter( QskControl* ); + protected: + void focusInEvent( QFocusEvent* ); + private: class PrivateData; std::unique_ptr< PrivateData > m_data;