Is there a way to get QFontMetrics from for example a QLabel where the font was set with a stylesheet?
Is there a way to get QFontMetrics from for example a QLabel where the font was set with a stylesheet?
What did you already try to achieve the goal?
With a stylesheet I have set the QLabel mainlabel to Arial but QFontMetrics sees "MS Shell Dlg 2"...Qt Code:
{ { /* Change the font size to make it fit... */ }; this->mainLabel->setText(mainText); this->mainLabel->setAlignment(alignment); };To copy to clipboard, switch view to plain text mode
I think the text doesn't depend on the font size, thus you should adjust the font size while drawing the text and not when setting it on the widget. And probably when you do, you'll have the proper font set up on the painter or at least in the style option initialized from the widget. Text size doesn't make sense outside painting routines. The label won't even have the width calculated before it is first shown and I guess you'd want to have a possibility to call this method before the widget is shown.
The QLabels are sized and drawn on screen and the text is set afterwards. So I know it's width and should be able to resize the text when I know the font size. What I understand from what you say is that as long no text is drawn the label will not have the font set? I think it's strange cause it has also a border and background that is set correctly...
Let me rephrase - it is possible that font metrics point to the proper font only from within paintEvent and its QStyleOption object. But it's a wild guess, so you should verify that.
How do you check that?think it's strange cause it has also a border and background that is set correctly...
Hi,
I am facing similar problem, pl. see http://www.qtcentre.org/threads/2731...ached-program)
In above toy program, I am setting font size to 20 as stylesheet to QApplication; but when taking QFontMetrics of mainwindow or dialog it gives me size '9'.
In my actual application, I am allowing user to change the font size of the entire application via style sheet; and for sime tableviews / QComboBoxes / QToolbars I am using QFontMetrics (for which I am getting wrong QFontMetrics information).
Please suggest if there is any alternate way to 'allow user to set font of entire application'.
Thank you in advance.
-Hiral
Bookmarks