View Full Version : QFontMetrics, i can't understand
pakulo
22nd June 2007, 07:31
QFont font;
font.setBold(true);
std::cout<<QFontMetrics(font).width("...");
Writed 9.
QFont font;
std::cout<<QFontMetrics(font).width("...");
Writed 12.
Why if font is bold the width is smaller then if font is nobold?
jacek
22nd June 2007, 12:10
It seems to work OK on my system. Which Qt version and what font do you use?
pakulo
22nd June 2007, 16:53
Qt 4.3
I use only this code
QFont font2;
std::cout<<QFontMetrics(font2).width("...")<<"\n";
font2.setBold(true);
font2.setItalic(true);
std::cout<<QFontMetrics(font2).width("...");
And it is write
12
9
pakulo
22nd June 2007, 16:56
if i don't use font2.setBold(true);
it is write
12
12
jacek
22nd June 2007, 18:50
I've just tried it on windows, and indeed I got 12 and 9, but if you start Qt Designer and compare two labels (one with normal font and second with bold font), you'll see it's a correct result for the default font.
pakulo
24th June 2007, 09:57
it is a bug of the Qt?
marcel
24th June 2007, 10:32
I've just tried it on windows, and indeed I got 12 and 9, but if you start Qt Designer and compare two labels (one with normal font and second with bold font), you'll see it's a correct result for the default font.
I can't confirm this with 4.3 on XP. A bold text has a bigger width than the same text, not bold.
I'll try to see what QFontMetrics returns.
Regards
marcel
24th June 2007, 11:04
fmetrics::fmetrics(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
QFontMetrics metrics(ui.label->font());
QFontMetrics metrics2(ui.label_2->font());
qDebug( QString("%1").arg(metrics.width(ui.label->text())).toAscii().constData() );
qDebug( QString("%1").arg(metrics2.width(ui.label_2->text())).toAscii().constData() );
}
label and label_2 are two QLabels with the same font set. One has normal font and the other has a bold font.
I always get a smaller width for the label with normal font. I tried with several fonts.
What font did you use?
Regards
jacek
24th June 2007, 15:30
it is a bug of the Qt?
No, everything is OK. It's just a property of a font you have used.
1311
jacek
24th June 2007, 15:31
I can't confirm this with 4.3 on XP.
Try it on "..." and MS Shell Dlg 2 font.
marcel
24th June 2007, 17:41
Yes, with "..." I get the same result.
But with other font families this seems to be OK.
Anyway, I don't see a real problem even with MS Shell Dlg 2, as long as the dimensions are correct( which they are ).
So, there must be a glitch in the font.
Regards
jacek
24th June 2007, 17:59
So, there must be a glitch in the font.
There is no glitch. Simply MS Shell Dlg 2 behaves this way.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.