Skip to content

Commit c33e6ff

Browse files
committedSep 14, 2012
fix alignment when using oxygen (kde) theme
1 parent 4fa28d8 commit c33e6ff

File tree

1 file changed

+47
-6
lines changed

1 file changed

+47
-6
lines changed
 

‎src/gui/qgscollapsiblegroupbox.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ void QgsCollapsibleGroupBox::saveState()
152152
{
153153
if ( ! mSaveState )
154154
return;
155-
QgsDebugMsg( "key = " + saveKey() + " objectName = " + objectName() );
156155
QSettings settings;
157156
QString key = saveKey();
158157
settings.setValue( key + "/checked", isChecked() );
@@ -178,24 +177,66 @@ void QgsCollapsibleGroupBox::updateStyle()
178177
{
179178
setUpdatesEnabled( false );
180179

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
182220
// TODO: move to app stylesheet system, when appropriate
183221
QString ss;
184222
ss += "QgsCollapsibleGroupBox::title {";
185223
ss += " subcontrol-origin: margin;";
186224
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 );
189229
ss += "}";
190230
setStyleSheet( ss );
191231

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
194233
QString ssd;
195234
ssd = QString( "QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg( mCollapseButton->objectName() );
196235
ssd += " background-color: rgba(255, 255, 255, 0); border: none;";
197236
ssd += "}";
198237
mCollapseButton->setStyleSheet( ssd );
238+
if ( offsetLeft != 0 || offsetTop2 != 0 )
239+
mCollapseButton->move( offsetLeft, offsetTop2 );
199240

200241
setUpdatesEnabled( true );
201242
}

0 commit comments

Comments
 (0)
Please sign in to comment.