@@ -29,14 +29,14 @@ QIcon QgsCollapsibleGroupBox::mCollapseIcon;
29
29
QIcon QgsCollapsibleGroupBox::mExpandIcon ;
30
30
31
31
QgsCollapsibleGroupBox::QgsCollapsibleGroupBox ( QWidget *parent )
32
- : QGroupBox( parent ), mCollapsed( false ), mSaveState( true )
32
+ : QGroupBox( parent )
33
33
{
34
34
init ();
35
35
}
36
36
37
37
QgsCollapsibleGroupBox::QgsCollapsibleGroupBox ( const QString &title,
38
38
QWidget *parent )
39
- : QGroupBox( title, parent ), mCollapsed( false ), mSaveState( true )
39
+ : QGroupBox( title, parent )
40
40
{
41
41
init ();
42
42
}
@@ -48,6 +48,12 @@ QgsCollapsibleGroupBox::~QgsCollapsibleGroupBox()
48
48
49
49
void QgsCollapsibleGroupBox::init ()
50
50
{
51
+ // variables
52
+ mCollapsed = false ;
53
+ mSaveState = true ;
54
+ mInitFlat = false ;
55
+ mShown = false ;
56
+
51
57
// init icons
52
58
if ( mCollapseIcon .isNull () )
53
59
{
@@ -70,11 +76,22 @@ void QgsCollapsibleGroupBox::init()
70
76
71
77
void QgsCollapsibleGroupBox::showEvent ( QShowEvent * event )
72
78
{
79
+ // initialise widget on first show event only
80
+ if ( mShown )
81
+ {
82
+ event->accept ();
83
+ return ;
84
+ }
85
+ mShown = true ;
86
+
87
+ // check if groupbox was set to flat in Designer or in code
88
+ mInitFlat = isFlat ();
89
+
73
90
loadState ();
74
91
75
92
updateStyle ();
76
93
77
- // expand if needed - any calls to setCollapsed() before only set mCollapsed
94
+ // expand if needed - any calls to setCollapsed() before only set mCollapsed, but have UI effect
78
95
if ( mCollapsed )
79
96
{
80
97
setCollapsed ( mCollapsed );
@@ -85,6 +102,7 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
85
102
still emit signal for connections using expanded state */
86
103
emit collapsedStateChanged ( this );
87
104
}
105
+
88
106
event->accept ();
89
107
}
90
108
@@ -249,9 +267,12 @@ void QgsCollapsibleGroupBox::setCollapsed( bool collapse )
249
267
return ;
250
268
251
269
// for consistent look/spacing across platforms when collapsed
252
- setFlat ( collapse );
270
+ if ( ! mInitFlat ) // skip if initially set to flat in Designer
271
+ setFlat ( collapse );
272
+
253
273
// avoid flicker in X11
254
274
QApplication::processEvents ();
275
+
255
276
// set maximum height to hide contents - does this work in all envs?
256
277
// setMaximumHeight( collapse ? 25 : 16777215 );
257
278
setMaximumHeight ( collapse ? titleRect ().bottom () + 6 : 16777215 );
0 commit comments