Results 1 to 4 of 4

Thread: Set semi-transparent background on QwtPlotZoomer RectRubberBand

  1. #1
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:
    Qt Code:
    1. PlotZoomer::PlotZoomer(int xAxis, int yAxis, QwtPlotCanvas* canvas) : QwtPlotZoomer(xAxis,yAxis,canvas)
    2. {
    3. QBrush brush(Qt::darkBlue);
    4. QPen pen(brush,5,Qt::DotLine);
    5. setRubberBandPen(pen);
    To copy to clipboard, switch view to plain text mode 

    Thank you in advance!

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

    Default Re: Set semi-transparent background on QwtPlotZoomer RectRubberBand

    Qt Code:
    1. virtual void PlotZoomer::drawRubberBand( QPainter *painter ) const
    2. {
    3. QColor c( Qt::darkBlue );
    4. c.setAlpha( 128 );
    5.  
    6. painter->setBrush( c );
    7. QwtPlotZoomer::drawRubberBand( painter );
    8. }
    To copy to clipboard, switch view to plain text mode 

    Note that this code works for alpha values >= 128 only. A solutions supporting all alpha values would look like this:

    Qt Code:
    1. virtual void drawRubberBand( QPainter *painter ) const
    2. {
    3. if ( dynamic_cast< const QBitmap *>( painter->device() ) )
    4. {
    5. painter->setBrush( Qt::color1 );
    6. }
    7. else
    8. {
    9. QColor c( Qt::darkBlue );
    10. c.setAlpha( 60 );
    11.  
    12. painter->setBrush( c );
    13. }
    14.  
    15. QwtPlotZoomer::drawRubberBand( painter );
    16. }
    To copy to clipboard, switch view to plain text mode 
    Uwe

  3. The following user says thank you to Uwe for this useful post:

    missoni (10th May 2012)

  4. #3
    Join Date
    Apr 2011
    Location
    Bayreuth, Bayern
    Posts
    24
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default 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!

  5. #4
    Join Date
    Dec 2013
    Posts
    15
    Thanks
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default 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?

Similar Threads

  1. Can QDockWidget be semi-transparent?
    By PolyVox in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2009, 20:09
  2. Non-transparent QWidget on semi-transparent parent
    By EuroElessar in forum Qt Programming
    Replies: 0
    Last Post: 29th August 2008, 16:20
  3. Semi-Transparent Background on Widget?
    By JimDaniel in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2008, 18:19
  4. Semi transparent QDialog
    By cs_raja in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 10:14
  5. QTextEdit with semi-transparent background
    By ber_44 in forum Qt Programming
    Replies: 6
    Last Post: 29th April 2007, 00:01

Tags for this Thread

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.