@@ -49,41 +49,25 @@ void QgsCollapsibleGroupBox::init()
49
49
mExpandIcon = QgsApplication::getThemeIcon ( " /mIconExpand.png" );
50
50
}
51
51
52
- // customize style sheet
53
- // TODO: move to app stylesheet system, when appropriate
54
- QString ss;
55
- ss += " QgsCollapsibleGroupBox::title {" ;
56
- ss += " subcontrol-origin: margin;" ;
57
- ss += " subcontrol-position: top left;" ;
58
- ss += " margin-left: 20px;" ; // offset for disclosure triangle
59
- ss += " margin-right: 5px;" ; // a little bit of space on the right, to match space on the left
60
- ss += " }" ;
61
- setStyleSheet ( ss );
62
-
63
52
// collapse button
64
53
mCollapseButton = new QToolButton ( this );
65
54
mCollapseButton ->setObjectName ( " collapseButton" );
66
55
mCollapseButton ->setAutoRaise ( true );
67
56
mCollapseButton ->setFixedSize ( 16 , 16 );
68
- // TODO set size (as well as margins) depending on theme
57
+ // TODO set size (as well as margins) depending on theme, in updateStyle()
69
58
mCollapseButton ->setIconSize ( QSize ( 12 , 12 ) );
70
59
mCollapseButton ->setIcon ( mCollapseIcon );
71
60
72
- // clear toolbutton default background and border
73
- // TODO: move to app stylesheet system, when appropriate
74
- QString ssd;
75
- ssd = QString ( " QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg ( mCollapseButton ->objectName () );
76
- ssd += " background-color: rgba(255, 255, 255, 0); border: none;" ;
77
- ssd += " }" ;
78
- mCollapseButton ->setStyleSheet ( ssd );
79
-
80
61
connect ( mCollapseButton , SIGNAL ( clicked () ), this , SLOT ( toggleCollapsed () ) );
81
62
connect ( this , SIGNAL ( toggled ( bool ) ), this , SLOT ( checkToggled ( bool ) ) );
82
63
}
83
64
84
65
void QgsCollapsibleGroupBox::showEvent ( QShowEvent * event )
85
66
{
86
67
QGroupBox::showEvent ( event );
68
+
69
+ updateStyle ();
70
+
87
71
// expand if needed - any calls to setCollapsed() before only set mCollapsed
88
72
if ( mCollapsed )
89
73
{
@@ -102,11 +86,7 @@ void QgsCollapsibleGroupBox::mouseReleaseEvent( QMouseEvent *event )
102
86
// catch mouse release over title when non checkable, to collapse/expand
103
87
if ( !isCheckable () && event->button () == Qt::LeftButton )
104
88
{
105
- QStyleOptionGroupBox box;
106
- initStyleOption ( &box );
107
- QRect rect = style ()->subControlRect ( QStyle::CC_GroupBox, &box,
108
- QStyle::SC_GroupBoxLabel, this );
109
- if ( rect.contains ( event->pos () ) )
89
+ if ( mTitleRect .contains ( event->pos () ) )
110
90
{
111
91
toggleCollapsed ();
112
92
return ;
@@ -131,6 +111,39 @@ void QgsCollapsibleGroupBox::toggleCollapsed()
131
111
setCollapsed ( !mCollapsed );
132
112
}
133
113
114
+ void QgsCollapsibleGroupBox::updateStyle ()
115
+ {
116
+ setUpdatesEnabled ( false );
117
+
118
+ // customize style sheet
119
+ // TODO: move to app stylesheet system, when appropriate
120
+ QString ss;
121
+ ss += " QgsCollapsibleGroupBox::title {" ;
122
+ ss += " subcontrol-origin: margin;" ;
123
+ ss += " subcontrol-position: top left;" ;
124
+ ss += " margin-left: 20px;" ; // offset for disclosure triangle
125
+ ss += " margin-right: 5px;" ; // a little bit of space on the right, to match space on the left
126
+ ss += " }" ;
127
+ setStyleSheet ( ss );
128
+
129
+ // clear toolbutton default background and border
130
+ // TODO: move to app stylesheet system, when appropriate
131
+ QString ssd;
132
+ ssd = QString ( " QgsCollapsibleGroupBox > QToolButton#%1 {" ).arg ( mCollapseButton ->objectName () );
133
+ ssd += " background-color: rgba(255, 255, 255, 0); border: none;" ;
134
+ ssd += " }" ;
135
+ mCollapseButton ->setStyleSheet ( ssd );
136
+
137
+ setUpdatesEnabled ( true );
138
+
139
+ // init title rect for later use - should not change during execution
140
+ // if it needs updating (e.g. in options dlg), call slot when style changes
141
+ QStyleOptionGroupBox box;
142
+ initStyleOption ( &box );
143
+ mTitleRect = style ()->subControlRect ( QStyle::CC_GroupBox, &box,
144
+ QStyle::SC_GroupBoxLabel, this );
145
+ }
146
+
134
147
void QgsCollapsibleGroupBox::setCollapsed ( bool collapse )
135
148
{
136
149
mCollapsed = collapse;
@@ -142,8 +155,9 @@ void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
142
155
setFlat ( collapse );
143
156
// avoid flicker in X11
144
157
QApplication::processEvents ();
145
- // set maximum height to 25 to hide contents - does this work in all envs?
146
- setMaximumHeight ( collapse ? 25 : 16777215 );
158
+ // set maximum height to hide contents - does this work in all envs?
159
+ // setMaximumHeight( collapse ? 25 : 16777215 );
160
+ setMaximumHeight ( collapse ? mTitleRect .height () + 2 : 16777215 );
147
161
mCollapseButton ->setIcon ( collapse ? mExpandIcon : mCollapseIcon );
148
162
149
163
emit collapsedStateChanged ( this );
0 commit comments