@@ -152,7 +152,6 @@ void QgsCollapsibleGroupBox::saveState()
152
152
{
153
153
if ( ! mSaveState )
154
154
return ;
155
- QgsDebugMsg ( " key = " + saveKey () + " objectName = " + objectName () );
156
155
QSettings settings;
157
156
QString key = saveKey ();
158
157
settings.setValue ( key + " /checked" , isChecked () );
@@ -178,24 +177,66 @@ void QgsCollapsibleGroupBox::updateStyle()
178
177
{
179
178
setUpdatesEnabled ( false );
180
179
181
- // customize style sheet
180
+ // margin/offset defaults
181
+ int marginLeft = 20 ; // title margin for disclosure triangle
182
+ int marginRight = 5 ; // a little bit of space on the right, to match space on the left
183
+ int offsetLeft = 0 ; // offset for oxygen theme
184
+ int offsetTop = 0 ;
185
+ int offsetTop2 = 0 ; // offset for triangle
186
+
187
+ // calculate offset if frame overlaps triangle (oxygen theme)
188
+ // using an offset of 6 pixels from frame border
189
+ if ( QApplication::style ()->objectName ().toLower () == " oxygen" )
190
+ {
191
+ QStyleOptionGroupBox box;
192
+ initStyleOption ( &box );
193
+ QRect rectFrame = style ()->subControlRect ( QStyle::CC_GroupBox, &box,
194
+ QStyle::SC_GroupBoxFrame, this );
195
+ QRect rectCheckBox = style ()->subControlRect ( QStyle::CC_GroupBox, &box,
196
+ QStyle::SC_GroupBoxCheckBox, this );
197
+ if ( rectFrame.left () <= 0 )
198
+ offsetLeft = 6 + rectFrame.left ();
199
+ if ( rectFrame.top () <= 0 )
200
+ {
201
+ if ( isCheckable () )
202
+ {
203
+ // if is checkable align with checkbox
204
+ offsetTop = ( rectCheckBox.height () / 2 ) -
205
+ ( mCollapseButton ->height () / 2 ) + rectCheckBox.top ();
206
+ offsetTop2 = offsetTop + 1 ;
207
+ }
208
+ else
209
+ {
210
+ offsetTop = 6 + rectFrame.top ();
211
+ offsetTop2 = offsetTop;
212
+ }
213
+ }
214
+ }
215
+
216
+ QgsDebugMsg ( QString ( " groupbox: %1 style: %2 offset: left=%3 top=%4 top2=%5" ).arg (
217
+ objectName () ).arg ( QApplication::style ()->objectName () ).arg ( offsetLeft ).arg ( offsetTop ).arg ( offsetTop2 ) );
218
+
219
+ // customize style sheet for collapse/expand button and force left-aligned title
182
220
// TODO: move to app stylesheet system, when appropriate
183
221
QString ss;
184
222
ss += " QgsCollapsibleGroupBox::title {" ;
185
223
ss += " subcontrol-origin: margin;" ;
186
224
ss += " subcontrol-position: top left;" ;
187
- ss += " margin-left: 20px;" ; // offset for disclosure triangle
188
- ss += " margin-right: 5px;" ; // a little bit of space on the right, to match space on the left
225
+ ss += QString ( " margin-left: %1px;" ).arg ( marginLeft );
226
+ ss += QString ( " margin-right: %1px;" ).arg ( marginRight );
227
+ ss += QString ( " left: %1px;" ).arg ( offsetLeft );
228
+ ss += QString ( " top: %1px;" ).arg ( offsetTop );
189
229
ss += " }" ;
190
230
setStyleSheet ( ss );
191
231
192
- // clear toolbutton default background and border
193
- // TODO: move to app stylesheet system, when appropriate
232
+ // clear toolbutton default background and border and apply offset
194
233
QString ssd;
195
234
ssd = QString ( " QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg ( mCollapseButton ->objectName () );
196
235
ssd += " background-color: rgba(255, 255, 255, 0); border: none;" ;
197
236
ssd += " }" ;
198
237
mCollapseButton ->setStyleSheet ( ssd );
238
+ if ( offsetLeft != 0 || offsetTop2 != 0 )
239
+ mCollapseButton ->move ( offsetLeft, offsetTop2 );
199
240
200
241
setUpdatesEnabled ( true );
201
242
}
0 commit comments