Skip to content

Commit 2b7232c

Browse files
committed
Replace deprecated function call
QFontMetrics::width() has been deprecated. Using QFontMetrics::horizontalAdvance() is the proper way to go (introduce in Qt 5.11).
1 parent 0b88843 commit 2b7232c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ElidingLabel.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ QSize CElidingLabel::minimumSizeHint() const
157157
return QLabel::minimumSizeHint();
158158
}
159159
const QFontMetrics &fm = fontMetrics();
160-
QSize size(fm.width(d->Text.left(2) + ""), fm.height());
160+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
161+
QSize size(fm.horizontalAdvance(d->Text), QLabel::sizeHint().height());
162+
#else
163+
QSize size(fm.width(d->Text), QLabel::sizeHint().height());
164+
#endif
161165
return size;
162166
}
163167

@@ -170,7 +174,11 @@ QSize CElidingLabel::sizeHint() const
170174
return QLabel::sizeHint();
171175
}
172176
const QFontMetrics& fm = fontMetrics();
173-
QSize size(fm.width(d->Text), QLabel::sizeHint().height());
177+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
178+
QSize size(fm.horizontalAdvance(d->Text), QLabel::sizeHint().height());
179+
#else
180+
QSize size(fm.width(d->Text), QLabel::sizeHint().height());
181+
#endif
174182
return size;
175183
}
176184

0 commit comments

Comments
 (0)