Results 1 to 8 of 8

Thread: QRubberBand widget background transparent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,349
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    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.

  3. #3

    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 22:52.

  4. #4

    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, 14:25
  2. Custom QRubberBand with transparent background
    By mdomke in forum Qt Programming
    Replies: 1
    Last Post: 11th June 2010, 10:34
  3. Draw transparent SVG in Background of Widget
    By soul_rebel in forum Qt Programming
    Replies: 0
    Last Post: 28th October 2008, 20:44
  4. Semi-Transparent Background on Widget?
    By JimDaniel in forum Qt Programming
    Replies: 3
    Last Post: 16th January 2008, 18:19
  5. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17: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
  •  
Qt is a trademark of The Qt Company.