@@ -33,6 +33,9 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
33
33
: QWidget( parent )
34
34
, mMousePrecisionDecimalPlaces( 0 )
35
35
{
36
+ // calculate the size of two chars
37
+ mTwoCharSize = fontMetrics ().width ( QStringLiteral ( " OO" ) );
38
+
36
39
// add a label to show current position
37
40
mLabel = new QLabel ( QString (), this );
38
41
mLabel ->setObjectName ( QStringLiteral ( " mCoordsLabel" ) );
@@ -46,7 +49,6 @@ QgsStatusBarCoordinatesWidget::QgsStatusBarCoordinatesWidget( QWidget *parent )
46
49
47
50
mLineEdit = new QLineEdit ( this );
48
51
mLineEdit ->setMinimumWidth ( 10 );
49
- mLineEdit ->setMaximumWidth ( 300 );
50
52
// mLineEdit->setMaximumHeight( 20 );
51
53
mLineEdit ->setContentsMargins ( 0 , 0 , 0 , 0 );
52
54
mLineEdit ->setAlignment ( Qt::AlignCenter );
@@ -226,10 +228,7 @@ void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p )
226
228
mLineEdit ->setText ( QgsCoordinateUtils::formatCoordinateForProject ( p, mMapCanvas ->mapSettings ().destinationCrs (),
227
229
mMousePrecisionDecimalPlaces ) );
228
230
229
- if ( mLineEdit ->width () > mLineEdit ->minimumWidth () )
230
- {
231
- mLineEdit ->setMinimumWidth ( mLineEdit ->width () );
232
- }
231
+ ensureCoordinatesVisible ();
233
232
}
234
233
235
234
@@ -244,9 +243,19 @@ void QgsStatusBarCoordinatesWidget::showExtent()
244
243
QgsRectangle myExtents = mMapCanvas ->extent ();
245
244
mLabel ->setText ( tr ( " Extents:" ) );
246
245
mLineEdit ->setText ( myExtents.toString ( true ) );
247
- // ensure the label is big enough
248
- if ( mLineEdit ->width () > mLineEdit ->minimumWidth () )
246
+
247
+ ensureCoordinatesVisible ();
248
+ }
249
+
250
+ void QgsStatusBarCoordinatesWidget::ensureCoordinatesVisible ()
251
+ {
252
+
253
+ // ensure the label is big (and small) enough
254
+ int width = mLineEdit ->fontMetrics ().width ( mLineEdit ->text () ) + 10 ;
255
+ if ( mLineEdit ->minimumWidth () < width || ( mLineEdit ->minimumWidth () - width ) > mTwoCharSize )
249
256
{
250
- mLineEdit ->setMinimumWidth ( mLineEdit ->width () );
257
+ mLineEdit ->setMinimumWidth ( width );
258
+ mLineEdit ->setMaximumWidth ( width );
251
259
}
252
260
}
261
+
0 commit comments