making QskMainView a focus scope, so that the focus does not get lost,

when popups ( f.e menus ) have appeared
This commit is contained in:
Uwe Rathmann 2023-05-15 15:04:47 +02:00
parent e64e1b6cbb
commit 1f899ebdbf
2 changed files with 24 additions and 0 deletions

View File

@ -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"

View File

@ -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;