PDA

View Full Version : Setting QwtPlot's canvas as Transparent wthout stylesheet way?



umituzun84
15th March 2011, 16:54
Hi All,

How can I set my QwtPlot's canvas as transparent? I want to see all my running curves and canvas background in same screen. My settings like that;


plotHandle->canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, true);
plotHandle->canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false);

QPalette palette = plotHandle->canvas()->palette();
palette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 0)));
privateData.plotHandle->canvas()->setBackgroundRole(QPalette::Window);
privateData.plotHandle->canvas()->setPalette(palette);
privateData.plotHandle->canvas()->setAutoFillBackground(false);

But my canvas seem not transparent until I set the BackingStore attribute to false.
This time I can see background of canvas but replot function doesn't work and my curves draw's the same screen in overlapped way without cleaning the canvas.

How can I make my canvas transparent?
Thanks in advance.

Uwe
16th March 2011, 06:50
How can I set my QwtPlot's canvas as transparent? I want to see all my running curves and canvas background in same screen.
Having a semi-transparent ( or no ) background for the canvas will have the effect, that you can see the background of the parent - the plot widget. If you really want to see the background of the canvas through the curves you have to use semi transparent pens/brushes for the curves.

Note,that using semi transparent ( or no ) background for the plot canvas might be a serious performance issue and you have to change some widget attributes to disable optimizations - but at least in Qwt 6 it should be possible.

Uwe

umituzun84
16th March 2011, 08:40
Hi Uwe,

First of all thanks for reply.
I tried to make my canvas background semi transparent and transparent by;


plotHandle->setWindowOpacity(0);
plotHandle->setAttribute(Qt::WA_TranslucentBackground);
plotHandle->setCanvasBackground(QColor(0,0,0,0));
plotHandle->replot();


But this code block does't work, so I can't see behind my QwtPlot component's background where there is another widgets located.
How can I achieve this operation?
Thanks in advance.

Uwe
16th March 2011, 22:38
This code works here:


int main(int argc, char **argv)
{
QApplication a(argc, argv);

QColor c( Qt::gray );
c.setAlpha( 100 );

QPalette pal;
pal.setColor( QPalette::Window, c );

QwtPlot plot;
plot.setAttribute(Qt::WA_TranslucentBackground);
plot.setPalette( pal );

plot.canvas()->setAutoFillBackground( false );
plot.canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);

plot.resize(600,400);
plot.show();

return a.exec();
}

But of course disabling the backing store of the canvas is no good solution and I guess all types of rubberband and tracker won't work. I will check this later.

Uwe

umituzun84
29th March 2011, 07:48
Hi Uwe,

I had tried your suggested pattern to make my canvas transparent but unfortunately didn't worked. My expectation with transparent apperance in plotting with QwtPlotDirectPainter like osciloscope or refreshtest samples. Could you try your suggestion on osciloscope example to make canvas transparent. This is not working.

I have tested osciloscope sample with stylesheet like this code block;


QColor plotCanvasTransparency = QColor(0,0,0,0);
QString styleSheet = QString("background-color: rgba(%1, %2, %3, %4);").arg(plotCanvasTransparency.red())
.arg(plotCanvasTransparency.green())
.arg(plotCanvasTransparency.blue())
.arg(plotCanvasTransparency.alpha());
canvas()->setStyleSheet(styleSheet);


First try to paste this code block on plot.cpp's constructor and run the example; you will see that canvas is transparent now. But if you locate one widget (for example QPushButton) background of QwtPlot you can't see this widget altought you have set your canvas to be transparent in constructor.

Second try to paste this code block on end of plot.cpp's incrementInterval function.
You will see that after incrementInterval function called curve plotting started to flicker awkwardly as you can watch this link (http://img801.imageshack.us/i/2c5.mp4/).

I need to make my canvas transparent but can't success with stylesheet and using QwtPlotDirectPainter.

Uwe
3rd April 2011, 11:12
With e following changes the oscilloscope example ( SVN trunk ) has a semi-transparent background on my Linux box with KDE4:

1) At the end of the MainWindow constructor you have to do:


setAttribute(Qt::WA_TranslucentBackground);

2) Set autoFillBackground for all parts, where you want to have background. f.e:


d_plot->setAutoFillBackground( true );

3) Now replace the implementation of Plot::initGradient


void Plot::initGradient()
{
QColor c( Qt::gray );
c.setAlpha( 50 );

QPalette pal;
pal.setColor( QPalette::Window, c );

canvas()->setPalette( pal );
canvas()->setAutoFillBackground( true );
}

Uwe

umituzun84
5th April 2011, 15:12
Hi Uwe;

First of all I represent my deep sincere to you for your reply.
I have already tried your suggestion. It seems transparent but when I add another widget behind the plotter, this translucent canvas isn't seem transparent as it should be.

For example, please add following code



QPushButton *pb = new QPushButton(this);
pb->setGeometry(100, 100, 100, 50);
pb->lower();


anywhere in MainWindow.cpp's constructor. And after you have run, if you can see widget which will be behind the canvas, that time this problem is related with me and forgive my foolish faults. If you won't see the background widget like me, please help me to solve this problem:)

I have tried to these steps, and can see background widget, but replot call in each interval doesn't erase the canvas anymore in this way;

Firstly revert the all changes in Oscilascope sample and then add following codes in plot.cpp's constructor.


canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false);
canvas()->setPaintAttribute(QwtPlotCanvas::HackStyledBackgro und, false);
canvas()->setPaintAttribute(QwtPlotCanvas::ImmediatePaint, true);


Then change initGradient as you suggested;


QColor c( Qt::gray );
c.setAlpha( 0 );
QPalette pal;
pal.setColor( QPalette::Window, c );
canvas()->setPalette( pal );
canvas()->setAutoFillBackground( true );


And add background widget which I have mentioned in the beginning of message in mainwindow's constructor again.

Then you can see the background widget which we have added to mainwindow already. But this time canvas refreshing problem occurs.

How can I make my canvas full transparent without kind of these awkward problems?

Thanks in advance Uwe.
İyi Günler :) (Have a nice day in Turkish)

Ãœmit Uzun

umituzun84
15th April 2011, 10:15
Hi Uwe;

Have you ever tried this situation?
I know you can't try special problem but I think this is not special problem, there would be someone who want to have full transparent canvas.

Thanks in advance.
Regards.

Ãœmit Uzun

Uwe
17th April 2011, 17:16
I have absolutely no idea, what you are looking for, but this sounds like you are talking about transparent backgrounds inside of the same application ( nothing, what has to to do with a composite manager ).

Add the following code to the constructor of Plot:


canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false);
canvas()->setAttribute( Qt::WA_OpaquePaintEvent, false );
canvas()->setAutoFillBackground( false );
Then remove all code from Plot::initGradient

Uwe