PDA

View Full Version : Changing the font size and the color of QwtPlot scale labels



Momergil
4th December 2014, 11:10
Hello!

I would like to know how do one change the Font (particularly the font size) of a QwtPlot's axis labels. Now notice I'm not talking here about the size of a QwtPlot Title, neither am I talking about the size of the title of the axis; I'm talking about the numbers that are displayed in the axis (0, 100,200, etc.). I just can't find the function to change that.

I would also like to change the color of the axis; for not it's white while the QwtPlot is with black background, and I would like to change the color to black when I put the background to white. I couldn't find the function for that either.

Any help would be appreciated.

Momergil

Uwe
4th December 2014, 11:40
The colors of the axes depends on the palette of the scale widget: QPalette::Text is used for the labels, QPalette::Foreground ( = QPalette::WindowText ) for ticks and backbone.
You can overrule the widget palette by overloading QwtAbstractScaleDraw::label(), where you can set individual colors for each tick label.

For your use case I would simply do something like "plot->setPalette( Qt::darkGray );". The constructor of QPalette will create colors with good contrasts and all scale widgets inherit the palette from the plot.

Concerning the font of the tick labels: "plot->axisWidget( ... )->setFont( ... );" Note, that the font can also be overruled in a similar way like the colors.

Uwe

Momergil
4th December 2014, 13:31
Hello Uwe! Thanks for the reply!

Now what you sad is what I was looking for - but it didn't work =T Or at least no properly...

Regarding the color, I'm being unable to change it neither by setting the scale widget's palette, nor by the general QwtPlot::setPalette(). The graph remains as it is. Any suggestions?

Concerning the font tick labels, the suggested code



QFont font = harmonicsGraph->axisWidget(QwtPlot::yLeft)->font();
font.setPointSize(50);
harmonicsGraph->axisWidget(QwtPlot::yLeft)->setFont(font);


doesn't work in the plot's constructor, only when the showEvent() is called (actually it doesn't work neither in the plot's constructor, nor in its parent's constructor, but in its parent's showEvent()). Was that supposed to happen? And, of course, the general setPalette doesn't work when inside the showEvent() and axis specific setPalette makes the axis dissapear =T.

Any suggestions on what may be happening of wrong?

Added after 1 7 minutes:

BTW, how to change the font and color size for QwtPolarPlot? I noticed that axisWidget() doesn't exist for that class.