setting the initial focus only on Qt::PopupFocusReason
This commit is contained in:
parent
d98317942e
commit
84d8c87309
|
@ -322,6 +322,42 @@ bool QskPopup::event( QEvent* event )
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QskPopup::focusInEvent( QFocusEvent* event )
|
||||||
|
{
|
||||||
|
Inherited::focusInEvent( event );
|
||||||
|
|
||||||
|
if ( isFocusScope() && isTabFence() && ( scopedFocusItem() == nullptr ) )
|
||||||
|
{
|
||||||
|
if ( event->reason() == Qt::PopupFocusReason )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
When receiving the focus we need to have a focused
|
||||||
|
item, so that the tab focus chain has a starting point.
|
||||||
|
|
||||||
|
But we only do it when the reason is Qt::PopupFocusReason
|
||||||
|
as we also receive focus events during the process of reparenting
|
||||||
|
children and setting the focus there can leave the item tree
|
||||||
|
in an invalid state.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ( auto focusItem = nextItemInFocusChain( true ) )
|
||||||
|
{
|
||||||
|
if ( qskIsItemComplete( focusItem )
|
||||||
|
&& qskIsAncestorOf( this, focusItem ) )
|
||||||
|
{
|
||||||
|
focusItem->setFocus( true );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void QskPopup::focusOutEvent( QFocusEvent* event )
|
||||||
|
{
|
||||||
|
Inherited::focusOutEvent( event );
|
||||||
|
}
|
||||||
|
|
||||||
QQuickItem* QskPopup::focusSuccessor() const
|
QQuickItem* QskPopup::focusSuccessor() const
|
||||||
{
|
{
|
||||||
if ( const auto scope = qskNearestFocusScope( this ) )
|
if ( const auto scope = qskNearestFocusScope( this ) )
|
||||||
|
|
|
@ -38,7 +38,10 @@ Q_SIGNALS:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void updateLayout() override;
|
virtual void updateLayout() override;
|
||||||
|
|
||||||
virtual bool event( QEvent* ) override;
|
virtual bool event( QEvent* ) override;
|
||||||
|
virtual void focusInEvent( QFocusEvent * ) override;
|
||||||
|
virtual void focusOutEvent( QFocusEvent * ) override;
|
||||||
|
|
||||||
virtual void itemChange( QQuickItem::ItemChange,
|
virtual void itemChange( QQuickItem::ItemChange,
|
||||||
const QQuickItem::ItemChangeData& ) override;
|
const QQuickItem::ItemChangeData& ) override;
|
||||||
|
|
Loading…
Reference in New Issue