Results 1 to 2 of 2

Thread: Font of a QwtScaleDraw label

  1. #1
    Join Date
    Jan 2020
    Posts
    3
    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,234
    Thanked 856 Times in 805 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)

Similar Threads

  1. X axis tick label - font size
    By junhonguk in forum Qwt
    Replies: 5
    Last Post: 26th April 2012, 15:15
  2. How to resize label font to fit size
    By P@u1 in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2011, 23:07
  3. Replies: 2
    Last Post: 15th July 2011, 07:25
  4. QwtScaleDraw align label to xaxis
    By kja in forum Qwt
    Replies: 1
    Last Post: 21st November 2010, 19: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, 10: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.