Results 1 to 8 of 8

Thread: QRubberBand widget background transparent

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Question QRubberBand widget background transparent

    Hello,

    I am trying to get rid of the half-transparent fill of the QRubberBand widget. I just want it transparent.
    What I already tried:

    Qt Code:
    1. QPalette p = _rubberBand->palette();
    2. p.setColor(QPalette::Background, Qt::transparent);
    3. _rubberBand->setPalette(p);
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. _rubberBand->setStyleSheet("background-color: rgba(0,0,0,0)");
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. _rubberBand->setPalette(Qt::transparent);
    2. _rubberBand->setAttribute(Qt::WA_NoSystemBackground);
    3. _rubberBand->setAttribute(Qt::WA_TranslucentBackground);
    4. _rubberBand->setAttribute(Qt::WA_TransparentForMouseEvents);
    To copy to clipboard, switch view to plain text mode 

    but there is no effect at all. The rectangle is always rendered the same way (see attachment)...

    How can I fix this?

    Thank you in advance.
    Attached Images Attached Images

  2. #2
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QRubberBand widget background transparent

    the way how it is rendered seems to be platform dependant, since there is no semi-transparent background when I compile/run the application on Linux or MAC.

  3. #3
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QRubberBand widget background transparent

    nobody got an idea?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRubberBand widget background transparent

    By default a rectangular rubber band (s is Rectangle) will use a mask, so that a small border of the rectangle is all that is visible. Some styles (e.g., native Mac OS X) will change this and call QWidget::setWindowOpacity() to make a semi-transparent filled selection rectangle.
    Try calling setWindowOpacity( 0.0 ) after you construct the rubber band.

  5. #5
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: QRubberBand widget background transparent

    Thank you for this tip, but it also has no effect at all.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QRubberBand widget background transparent

    Sounds like you are being defeated either by the OS or a style setting. Maybe try deriving from QRubberBand, overriding the paintEvent() and messing with the style option there before passing it to the base class for the actual painting.

  7. #7

    Default Re: QRubberBand widget background transparent

    For Android its a littlebit weird.
    But the Answer is simple.

    Subclass what you want...

    //constructor
    setWindowFlags(Qt::FramelessWindowHint); <--- In the constructor

    //paintEvent
    //IF YOU WANT IT SEMI TRANSPARENT ...
    //If you want it transparent only, you dont have to overide paintEvent. Then its enough to use Qt::FramelessWindowHint in a subclass. But a subclass is not needed

    void Example_Dialog:: paintEvent(QPaintEvent *)
    {
    QColor backgroundColor = palette().background().color();
    backgroundColor.setAlpha(216); // Use Alphachannel u want
    QPainter painter(this);
    painter.fillRect(rect(),backgroundColor);
    }

    Dont tested it with QRubberband, but I think it will work with all Object the usage of setWindowFlags is possible.
    Just set Qpalette with the customized Color dont work

    In Windows:
    setWindowOpacity(0.8);
    Last edited by jules1337; 23rd April 2016 at 23:52.

  8. #8

    Default Re: QRubberBand widget background transparent

    In some cases you need to set the original windowFlags and add Framelesswindowhint.

    I tested this with QMenu. Didnt work. But Framelesswindowhint is an important part too.

    For QMenu u have to set Framelesswindowhint and the old windowFlags. But have to delete the Popup windowflag on Android.
    You have to do 3 steps to immitate theese flags.
    On Android you have to set Framelesswindowhint and the old windowFlags But have to delete the Popup windowflag. Then you just have to edit the Stylesheet with an transparent or semitransparent background. No need for an paintevent.

    On Windows you just have to add the framelesswindowint , setAttribute(Qt::WA_TranslucentBackground) and have to set the stylesheet too.

Similar Threads

  1. Replies: 2
    Last Post: 6th October 2010, 15:25
  2. Custom QRubberBand with transparent background
    By mdomke in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2010, 11:34
  3. Draw transparent SVG in Background of Widget
    By soul_rebel in forum Qt Programming
    Replies: 0
    Last Post: 28th October 2008, 21:44
  4. Semi-Transparent Background on Widget?
    By JimDaniel in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2008, 19:19
  5. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 18:52

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.