Results 1 to 7 of 7

Thread: Font of a QwtScaleDraw label

  1. #1
    Join Date
    Jan 2020
    Posts
    4
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Font of a QwtScaleDraw label

    Hi,

    I want to overwrite an axis label (with a QLineEdit in z direction, not C++) in order to give the user a possibility to change axis boundaries directly on a label. I found that the axis labels don't use the applications font - please consider this program:

    Qt Code:
    1. #include <QApplication>
    2. #include <QMainWindow>
    3. #include "qwt_plot.h"
    4. #include <QDebug>
    5. #include "qwt_scale_draw.h"
    6. #include "qwt_text.h"
    7.  
    8.  
    9. class Demo : public QMainWindow
    10. {
    11. public:
    12. Demo(QWidget *parent = 0) : QMainWindow(parent){
    13. _plot = new QwtPlot(this);
    14. }
    15.  
    16. QwtPlot *plot() {
    17. return _plot;
    18. }
    19.  
    20. private:
    21. QwtPlot *_plot;
    22. };
    23.  
    24. int main(int argc, char *argv[])
    25. {
    26.  
    27. QApplication a(argc, argv);
    28.  
    29. Demo w;
    30. w.setFont(QFont("Arial"));
    31. w.show();
    32. qDebug() << "Plot" << w.plot()->font();
    33. qDebug() << "ScaleDraw label" << w.plot()->axisScaleDraw(QwtPlot::xBottom)->label(450).font();
    34. return a.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    This program gives the output:

    Plot QFont( "Arial,8.14286,-1,5,50,0,0,0,0,0" )
    ScaleDraw label QFont( "MS Shell Dlg 2,8.14286,-1,5,50,0,0,0,0,0" )

    So obviously the applications font isn't propagated to QwtScaleDraw. QwtScaleDraw is not a QWidget, so this must be done by hand actually. (feature request if it is not implemented in the mean time - I'm using qwt6.1.2)

    But back to the labels: if I use the font MS Shell Dlg on my QLineEdit, the text looks different from the other labels. I'm confused now: on the one hand the label says, MS Shell Dlg is used for rendering the text, on the other hand it doesn't look like MS Shell Dlg.

    How can I get the font used to render the labels?

    Best regards,
    Carsten

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Font of a QwtScaleDraw label

    In general each tick label can have its individual color and font, what can be done by QwtText::setFont. If no specific font has been assigned QwtScaleDraw::draw() uses the font, that has been assigned to the painter ( see QPainter::setFont() ) that is passed in as a parameter.

    In case of a QwtScaleWidget ( what is used by QwtPlot ) the painter is initialized with its font and can be changed by setting plot->axisWidget( ... )->setFont( ... );

    Setting the application font ( or the font of a parent ) only affects attributes of the font of a child, when they have not been explicitly set before. In case of QwtPlot it initializes the fonts of its scale widgets and if you want to have your QApplication::setFont call having an effect you probably need to reset the Qt::WA_SetFont flag.

    HTH,
    Uwe

  3. The following user says thank you to Uwe for this useful post:

    CarstenS (16th January 2020)

  4. #3
    Join Date
    Jun 2021
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Font of a QwtScaleDraw label

    Thank you, I had the same question.

  5. #4
    Join Date
    May 2021
    Posts
    5
    Qt products
    Qt3
    Platforms
    Android

    Default Re: Font of a QwtScaleDraw label

    Thank you for sharing your code and giving a detailed answer on this topic. I had a very similar problem with fonts. I didn't know about the effect on the font attributes of the child. In my case, I had a problem after I added Liberator Font to the library. Still, after reading your post, everything fell into place. Sometimes it's not intuitive at all when you need to add something of your own to the library. In general, few people think about it, but fonts are very important because they can convey the right tone or mood for the user. Anyway, thanks for your help again. I've spent quite a bit of time trying to fix this.
    Last edited by d_stranz; 11th June 2021 at 23:25. Reason: removed URL

  6. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Font of a QwtScaleDraw label

    @Wanda1YN: Last warning. This is your second strike. Do not post links to commercial web sites. I am starting to think you are not a real person, but a clever spambot. If it happens again, your account will be banned.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #6
    Join Date
    Jun 2021
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Font of a QwtScaleDraw label

    Quote Originally Posted by Wanda1YN View Post
    Thank you for sharing your code and giving a detailed answer on this topic. I had a very similar problem with fonts. I didn't know about the effect on the font attributes of the child. In my case, I had a problem after I added Liberator Font to the library. Still, after reading your post, everything fell into place. Sometimes it's not intuitive at all when you need to add something of your own to the library. In general, few people think about it, but fonts are very important because they can convey the right tone or mood for the user. Anyway, thanks for your help again. I've spent quite a bit of time trying to fix this.
    Thank you for helping with this question

  8. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Font of a QwtScaleDraw label

    So we appear to have two spambots at work. Both @Wanda1YN and @Borderdec are now on the radar.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. X axis tick label - font size
    By junhonguk in forum Qwt
    Replies: 5
    Last Post: 26th April 2012, 16:15
  2. How to resize label font to fit size
    By P@u1 in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2011, 00:07
  3. Replies: 2
    Last Post: 15th July 2011, 08:25
  4. QwtScaleDraw align label to xaxis
    By kja in forum Qwt
    Replies: 1
    Last Post: 21st November 2010, 20:55
  5. Change Font Color of Label and CheckBox
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 3
    Last Post: 15th June 2006, 11:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.