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:
Code:
#include <QApplication>
#include <QMainWindow>
#include "qwt_plot.h"
#include <QDebug>
#include "qwt_scale_draw.h"
#include "qwt_text.h"
{
public:
}
return _plot;
}
private:
};
int main(int argc, char *argv[])
{
Demo w;
w.
setFont(QFont("Arial"));
w.show();
qDebug() << "Plot" << w.plot()->font();
qDebug
() <<
"ScaleDraw label" << w.
plot()->axisScaleDraw
(QwtPlot::xBottom)->label
(450).
font();
return a.exec();
}
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
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
Re: Font of a QwtScaleDraw label
Thank you, I had the same question.
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.
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.
Re: Font of a QwtScaleDraw label
Quote:
Originally Posted by
Wanda1YN
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
Re: Font of a QwtScaleDraw label
So we appear to have two spambots at work. Both @Wanda1YN and @Borderdec are now on the radar.