Results 1 to 4 of 4

Thread: Semi-Transparent Background on Widget?

  1. #1
    Join Date
    Sep 2007
    Location
    Rome, GA
    Posts
    199
    Thanks
    14
    Thanked 41 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Semi-Transparent Background on Widget?

    I'm using my own style, subclassing QWindowsStyle, and I'd like to make the background of a QWidget semi-transparent.

    I've been re-drawing my own scrollbars and other widgets, so I'm somewhat familiar with QPainter and its setOpacity() method, but I can't seem to find the correct flag to override the QWidget's background.

    What I'd basically like to do is have the main window's background semi-transparent and all the other widgets inside it opaque.

    Can someone point me in the right direction?

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Semi-Transparent Background on Widget?

    Do you mean a top level window, or a widget with a parent?
    You might find this thread of interest.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Semi-Transparent Background on Widget?

    I am not sure how to make background transparent while all other widgets opaque.

    But if you want to change background color, you can use QWidget::setPalette( const QPalette &) . If you want to change opacity of the whole widget then QWidget::setWindowOpacity( qreal level )
    Hope this helps

  4. #4
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Semi-Transparent Background on Widget?

    Don't forget setAutoFillBackground(true) if you change the background color in palette. Without that property, your widget will not draw its background.

Similar Threads

  1. How to Transparent QGraphicsView widget Background?
    By ashukla in forum Qt Programming
    Replies: 31
    Last Post: 6th March 2010, 11:35
  2. Graphics widget with background
    By ad5xj in forum Newbie
    Replies: 2
    Last Post: 24th August 2007, 16:29
  3. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  4. Replies: 3
    Last Post: 8th December 2006, 18:51
  5. Replies: 1
    Last Post: 5th April 2006, 16:44

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.