File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,33 @@ void QgsGpsToolBar::updateLocationLabel()
301
301
}
302
302
303
303
mInformationButton ->setText ( parts.join ( ' ' ) );
304
+
305
+ // ensure the label is big (and small) enough
306
+ const int width = mInformationButton ->fontMetrics ().boundingRect ( mInformationButton ->text () ).width () + 16 ;
307
+ bool allowResize = false ;
308
+ if ( mIsFirstSizeChange )
309
+ {
310
+ allowResize = true ;
311
+ }
312
+ else if ( mInformationButton ->minimumWidth () < width )
313
+ {
314
+ // always immediately grow to fit
315
+ allowResize = true ;
316
+ }
317
+ else if ( ( mInformationButton ->minimumWidth () - width ) > mInformationButton ->fontMetrics ().averageCharWidth () * 2 )
318
+ {
319
+ // only allow shrinking when a sufficient time has expired since we last resized.
320
+ // this avoids extraneous shrinking/growing resulting in distracting UI changes
321
+ allowResize = mLastLabelSizeChangeTimer .hasExpired ( 5000 );
322
+ }
323
+
324
+ if ( allowResize )
325
+ {
326
+ mInformationButton ->setMinimumWidth ( width );
327
+ mInformationButton ->setMaximumWidth ( width );
328
+ mLastLabelSizeChangeTimer .restart ();
329
+ mIsFirstSizeChange = false ;
330
+ }
304
331
}
305
332
306
333
adjustSize ();
Original file line number Diff line number Diff line change 18
18
19
19
#include < QToolBar>
20
20
#include < QPointer>
21
+ #include < QElapsedTimer>
21
22
22
23
#include " qgscoordinatereferencesystem.h"
23
24
#include " qgssettingsentryenumflag.h"
@@ -89,6 +90,9 @@ class QgsGpsToolBar : public QToolBar
89
90
bool mEnableAddVertexButton = true ;
90
91
91
92
QgsMapLayerProxyModel *mDestinationLayerModel = nullptr ;
93
+
94
+ bool mIsFirstSizeChange = true ;
95
+ QElapsedTimer mLastLabelSizeChangeTimer ;
92
96
};
93
97
94
98
#endif // QGSGPSTOOLBAR_H
You can’t perform that action at this time.
0 commit comments