Using the Qt framework, how do I measure the width (in pixels) of a piece of text rendered with a given font/style?
See Question&Answers more detail:osUsing the Qt framework, how do I measure the width (in pixels) of a piece of text rendered with a given font/style?
See Question&Answers more detail:osYou can use QFontMetrics class - see the width() method which can give you the width of a given QString.
QFont myFont(fontName, fontSize);;
QString str("I wonder how wide this is?");
QFontMetrics fm(myFont);
int width=fm.width(str);