Skip to content

Commit c425493

Browse files
wonder-sknyalldawson
authored andcommitted
Fix misbehaving tooltips/click of layer tree indicators in some styles
(cherry picked from commit d849dd6)
1 parent 18c2a61 commit c425493

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/gui/layertree/qgslayertreeviewitemdelegate.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ void QgsLayerTreeViewItemDelegate::paint( QPainter *painter, const QStyleOptionV
107107
}
108108
}
109109

110+
static void _fixStyleOption( QStyleOptionViewItem &opt )
111+
{
112+
// This makes sure our delegate behaves correctly across different styles. Unfortunately there is inconsistency
113+
// in how QStyleOptionViewItem::showDecorationSelected is prepared for paint() vs what is returned from view's viewOptions():
114+
// - viewOptions() returns it based on style's SH_ItemView_ShowDecorationSelected hint
115+
// - for paint() there is extra call to QTreeViewPrivate::adjustViewOptionsForIndex() which makes it
116+
// always true if view's selection behavior is SelectRows (which is the default and our case with layer tree view)
117+
// So for consistency between different calls we override it to what we get in paint() method ... phew!
118+
opt.showDecorationSelected = true;
119+
}
110120

111121
bool QgsLayerTreeViewItemDelegate::helpEvent( QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index )
112122
{
@@ -122,6 +132,8 @@ bool QgsLayerTreeViewItemDelegate::helpEvent( QHelpEvent *event, QAbstractItemVi
122132
{
123133
QStyleOptionViewItem opt = option;
124134
initStyleOption( &opt, index );
135+
_fixStyleOption( opt );
136+
125137
QRect indRect = mLayerTreeView->style()->subElementRect( static_cast<QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView );
126138

127139
if ( indRect.contains( he->pos() ) )
@@ -157,6 +169,8 @@ void QgsLayerTreeViewItemDelegate::onClicked( const QModelIndex &index )
157169
QStyleOptionViewItem opt( mLayerTreeView->viewOptions() );
158170
opt.rect = mLayerTreeView->visualRect( index );
159171
initStyleOption( &opt, index );
172+
_fixStyleOption( opt );
173+
160174
QRect indRect = mLayerTreeView->style()->subElementRect( static_cast<QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView );
161175

162176
QPoint pos = mLayerTreeView->mLastReleaseMousePos;

0 commit comments

Comments
 (0)