Results 1 to 9 of 9

Thread: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

  1. #1
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    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;

    Qt Code:
    1. plotHandle->canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, true);
    2. plotHandle->canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false);
    3.  
    4. QPalette palette = plotHandle->canvas()->palette();
    5. palette.setBrush(QPalette::Window, QBrush(QColor(0, 0, 0, 0)));
    6. privateData.plotHandle->canvas()->setBackgroundRole(QPalette::Window);
    7. privateData.plotHandle->canvas()->setPalette(palette);
    8. privateData.plotHandle->canvas()->setAutoFillBackground(false);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    Quote Originally Posted by umituzun84 View Post
    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

  3. #3
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    Hi Uwe,

    First of all thanks for reply.
    I tried to make my canvas background semi transparent and transparent by;
    Qt Code:
    1. plotHandle->setWindowOpacity(0);
    2. plotHandle->setAttribute(Qt::WA_TranslucentBackground);
    3. plotHandle->setCanvasBackground(QColor(0,0,0,0));
    4. plotHandle->replot();
    To copy to clipboard, switch view to plain text mode 

    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.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    This code works here:

    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. QColor c( Qt::gray );
    6. c.setAlpha( 100 );
    7.  
    8. QPalette pal;
    9. pal.setColor( QPalette::Window, c );
    10.  
    11. QwtPlot plot;
    12. plot.setAttribute(Qt::WA_TranslucentBackground);
    13. plot.setPalette( pal );
    14.  
    15. plot.canvas()->setAutoFillBackground( false );
    16. plot.canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
    17.  
    18. plot.resize(600,400);
    19. plot.show();
    20.  
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    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

  5. #5
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    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;
    Qt Code:
    1. QColor plotCanvasTransparency = QColor(0,0,0,0);
    2. QString styleSheet = QString("background-color: rgba(%1, %2, %3, %4);").arg(plotCanvasTransparency.red())
    3. .arg(plotCanvasTransparency.green())
    4. .arg(plotCanvasTransparency.blue())
    5. .arg(plotCanvasTransparency.alpha());
    6. canvas()->setStyleSheet(styleSheet);
    To copy to clipboard, switch view to plain text mode 

    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.

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

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    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:

    Qt Code:
    1. setAttribute(Qt::WA_TranslucentBackground);
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. d_plot->setAutoFillBackground( true );
    To copy to clipboard, switch view to plain text mode 

    3) Now replace the implementation of Plot::initGradient

    Qt Code:
    1. void Plot::initGradient()
    2. {
    3. QColor c( Qt::gray );
    4. c.setAlpha( 50 );
    5.  
    6. QPalette pal;
    7. pal.setColor( QPalette::Window, c );
    8.  
    9. canvas()->setPalette( pal );
    10. canvas()->setAutoFillBackground( true );
    11. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

  7. #7
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    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

    Qt Code:
    1. QPushButton *pb = new QPushButton(this);
    2. pb->setGeometry(100, 100, 100, 50);
    3. pb->lower();
    To copy to clipboard, switch view to plain text mode 

    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.
    Qt Code:
    1. canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false);
    2. canvas()->setPaintAttribute(QwtPlotCanvas::HackStyledBackground, false);
    3. canvas()->setPaintAttribute(QwtPlotCanvas::ImmediatePaint, true);
    To copy to clipboard, switch view to plain text mode 

    Then change initGradient as you suggested;

    Qt Code:
    1. QColor c( Qt::gray );
    2. c.setAlpha( 0 );
    3. QPalette pal;
    4. pal.setColor( QPalette::Window, c );
    5. canvas()->setPalette( pal );
    6. canvas()->setAutoFillBackground( true );
    To copy to clipboard, switch view to plain text mode 

    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

  8. #8
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    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

  9. #9
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Setting QwtPlot's canvas as Transparent wthout stylesheet way?

    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:

    Qt Code:
    1. canvas()->setPaintAttribute(QwtPlotCanvas::BackingStore, false);
    2. canvas()->setPaintAttribute(QwtPlotCanvas::Opaque, false);
    3. canvas()->setAttribute( Qt::WA_OpaquePaintEvent, false );
    4. canvas()->setAutoFillBackground( false );
    To copy to clipboard, switch view to plain text mode 
    Then remove all code from Plot::initGradient

    Uwe

Similar Threads

  1. QwtPlot Canvas Size Hint?
    By umituzun84 in forum Qwt
    Replies: 8
    Last Post: 22nd September 2011, 16:21
  2. Replies: 0
    Last Post: 4th May 2010, 09:45
  3. Setting QDial background image using stylesheet
    By dpatel in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2010, 13:13
  4. Replies: 1
    Last Post: 29th November 2008, 12:37
  5. Setting focus on Canvas
    By Kapil in forum Qt Programming
    Replies: 10
    Last Post: 17th May 2006, 12:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.