Set semi-transparent background on QwtPlotZoomer RectRubberBand
Hello!
I guess this must be a pretty easy question, but I cannot answer it without your help. I want to draw a semi-transparent background on the zoom rectangle of the QwtPlotZoomer. I have tried setting QPen and QBrush, but this only changed the rubberband line style, not the interior of the selection rectangle.
My code as of now is:
Code:
{
QPen pen
(brush,
5,Qt
::DotLine);
setRubberBandPen(pen);
Thank you in advance!
Re: Set semi-transparent background on QwtPlotZoomer RectRubberBand
Code:
virtual void PlotZoomer
::drawRubberBand( QPainter *painter
) const {
c.setAlpha( 128 );
painter->setBrush( c );
}
Note that this code works for alpha values >= 128 only. A solutions supporting all alpha values would look like this:
Code:
virtual void drawRubberBand
( QPainter *painter
) const {
if ( dynamic_cast<
const QBitmap *>
( painter
->device
() ) ) {
painter->setBrush( Qt::color1 );
}
else
{
c.setAlpha( 60 );
painter->setBrush( c );
}
}
Uwe
Re: Set semi-transparent background on QwtPlotZoomer RectRubberBand
Dear Uwe,
thank you for your fast reply! Strangely enough, the first code snippet did not bring by any changes, but the second code worked exactly the way I had wished!
Re: Set semi-transparent background on QwtPlotZoomer RectRubberBand
Both solutions don't work for me (code compiles but nothing changes) could you please tell me why and what can i do?