Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.8, 5.11, 5.12.0
-
None
Description
We were using Qt5.3 in our project, here all the strings in QLabel are fitting perfectly.
Now we planed to move to higher versions, but now we have problem with some Qt versions(Qt5.8/5.11/5.12) that strings are not fitting in QLabel, because here we are setting QFontMetrics::width() to QLabel width.
As I debugged QFontMetrics::width() is returning different value in different Qt version.
I am trying with below sample code to debug, I am using QFontMetricsF to get the accurate value of text width.
QFont font = ui->label->font();
font.setPixelSize(38);
QFontMetricsF fmf(font);
qDebug() << fmf.width("ii");
With the above code I got major different of width for below 3 strings(char i/l/T) .
string | Qt5.3 | Qt5.8/5.11/5.12 |
---|---|---|
"ii" | 16.1719 | 15.7188 |
"ll" | 15.75 | 15.7188 |
"TT" | 29.0313 | 28.9375 |
I got to know that QFontMetrics::width() is deprecated in Qt5.11/5.12.
I tried with QFontMetrics::horizontalAdvance() but it is also giving same result as width().