QwtPlot: how to set the canvas background colour to a semi-transparent?
-
Hi,
I have a
QwtPlot
object and I want and need to change its canvas background colour. To that end, I do something like:QBrush brush = canvasBackground(); brush.setColor(myColor); setCanvasBackground(brush);
This works fine with opaque colours, but if I have a semi-transparent colour (e.g.
#3a108080
), then the effective colour becomes that of its corresponding opaque colour (i.e.#108080
). Yet, if I query the canvas background colour, I correctly get#3a108080
...!?So, what am I doing wrong here?...
FWIW, I have managed to get things to work as I want by replacing the above code with:
setStyleSheet(QString("QwtPlotCanvas {" " background: %1;" "}").arg(myColor.name(QColor::HexArgb)));
Now, although it works fine, I must confess that I would rather avoid having to use style sheets. So, any idea how I achieve the same result using something like my original code?
Cheers, Alan.
-
Actually, to use style sheets is not right for what I want since I want the semi-transparent colour to be on a white background, while my QwtPlot object has a grey background...
This means that, in the end, I am doing the following:
static const QColor White = Qt::white; QBrush brush = canvasBackground(); double ratio = myColor.alpha()/256.0; brush.setColor(QColor((1.0-ratio)*White.red()+ratio*myColor.red(), (1.0-ratio)*White.green()+ratio*myColor.green(), (1.0-ratio)*White.blue()+ratio*myColor.blue())); setCanvasBackground(brush);
I guess I am happy with that...