PDA

View Full Version : qwt setCanvasBackground() won't



MrGarbage
18th August 2007, 05:16
I am using qwt to do some graphing.

I have a qwt plot on a stacked widget page. Everything in the graph
displays properly but for some reason I cannot set the background color.

I've successfully done it from in a test app that doesn't use the stackedwidget.

I also noticed that if I have > 1 qwtplot, ie another plot on a different page and
I set both of them, then one of them would get the background changed
but not both.

I'm doing:

Output_Graph->setCanvasBackground(QColor(Qt::darkBlue));

Any ideas? I'm going bonkers...

Mark

Sintegrial
15th June 2016, 11:57
Qwt 6.1.2, Windows 7, Qt 5.3.1 - the same issue.

setCanvasBackground() seems to do nothing at all.

Uwe
15th June 2016, 14:18
setCanvasBackground() had once been introduced for the designer, where you need to have a property.
But when looking at the implementation you will probably see, what goes wrong - maybe setting another canvas later.


void QwtPlot::setCanvasBackground( const QBrush &brush )
{
QPalette pal = canvas()->palette();
pal.setBrush( QPalette::Window, brush );

canvas()->setPalette( pal );
} Uwe

Sintegrial
15th June 2016, 15:01
Unfortunately this seems to have no effect on my PC...

After many experiments the only way to set plot and canvas backgrounds properly, was the following:

QString styleSheet("background: gray; color: yellow;");
plot->setStyleSheet(styleSheet);
plot->canvas()->setStyleSheet(styleSheet);

The application has its own custom style sheet which is set globally, so probably that could be the reason why just changing plotter's palette has no effect.

Uwe
15th June 2016, 15:10
The application has its own custom style sheet which is set globally, so probably that could be the reason why just changing plotter's palette has no effect.
Sure, styleSheets disable the palette in general. When using style sheets you can expect to have more of these conflicts - it was a questionable concept from the very beginning and maximal annoying for 3rd party libs.
But anyway under examples/stylesheets you find a couple of examples for how to manipulate QwtPlot widgets using style sheets.

Uwe