@@ -107,6 +107,16 @@ void QgsLayerTreeViewItemDelegate::paint( QPainter *painter, const QStyleOptionV
107
107
}
108
108
}
109
109
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
+ }
110
120
111
121
bool QgsLayerTreeViewItemDelegate::helpEvent ( QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index )
112
122
{
@@ -122,6 +132,8 @@ bool QgsLayerTreeViewItemDelegate::helpEvent( QHelpEvent *event, QAbstractItemVi
122
132
{
123
133
QStyleOptionViewItem opt = option;
124
134
initStyleOption ( &opt, index );
135
+ _fixStyleOption ( opt );
136
+
125
137
QRect indRect = mLayerTreeView ->style ()->subElementRect ( static_cast <QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView );
126
138
127
139
if ( indRect.contains ( he->pos () ) )
@@ -157,6 +169,8 @@ void QgsLayerTreeViewItemDelegate::onClicked( const QModelIndex &index )
157
169
QStyleOptionViewItem opt ( mLayerTreeView ->viewOptions () );
158
170
opt.rect = mLayerTreeView ->visualRect ( index );
159
171
initStyleOption ( &opt, index );
172
+ _fixStyleOption ( opt );
173
+
160
174
QRect indRect = mLayerTreeView ->style ()->subElementRect ( static_cast <QStyle::SubElement>( QgsLayerTreeViewProxyStyle::SE_LayerTreeItemIndicator ), &opt, mLayerTreeView );
161
175
162
176
QPoint pos = mLayerTreeView ->mLastReleaseMousePos ;
0 commit comments