Results 1 to 14 of 14

Thread: Set transparency without setting background color

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Set transparency without setting background color

    Quote Originally Posted by wysota View Post
    You can subclass, reimplement the paint event and use QPainter::setOpacity() before calling the base class implementation.
    Qt Code:
    1. QStylePainter p(this);
    2. p.setOpacity(0.1)M
    3. initStyleOption(&option);
    4. p.drawControl(QStyle::CE_PushButton, option);
    To copy to clipboard, switch view to plain text mode 

    Thanks! This works. But, that is the unique way to set transparency to a widget? Each widget I have to set some transparency I need to subclass it and replace the paintEvent function?

    Quote Originally Posted by aamer4yu View Post
    Or you can use QWidget::setWindowOpacity on the top level window
    That's for the window or for any widget? It didn't work for me. Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Set transparency without setting background color

    Quote Originally Posted by cdonts View Post
    Qt Code:
    1. QStylePainter p(this);
    2. p.setOpacity(0.1)M
    3. initStyleOption(&option);
    4. p.drawControl(QStyle::CE_PushButton, option);
    To copy to clipboard, switch view to plain text mode 

    Thanks! This works.
    I meant more like:

    Qt Code:
    1. class TranslucentButton : public QPushButton {
    2. // ...
    3. protected:
    4. void paintEvent(QPaintEvent *pe) {
    5. QPainter p(this);
    6. p.setOpacity(0.7);
    7. QPushButton::paintEvent(pe);
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 

    If it works, of course...

    But, that is the unique way to set transparency to a widget?
    You can also apply a QGraphicsOpacityEffect to a widget that will provide the transparency.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Set transparency without setting background color

    Quote Originally Posted by wysota View Post
    I meant more like:

    Qt Code:
    1. class TranslucentButton : public QPushButton {
    2. // ...
    3. protected:
    4. void paintEvent(QPaintEvent *pe) {
    5. QPainter p(this);
    6. p.setOpacity(0.7);
    7. QPushButton::paintEvent(pe);
    8. }
    9. };
    To copy to clipboard, switch view to plain text mode 

    If it works, of course...


    You can also apply a QGraphicsOpacityEffect to a widget that will provide the transparency.
    Fantastic! Thank you very much!

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

    Default Re: Set transparency without setting background color

    Quote Originally Posted by cdonts View Post
    That's for the window or for any widget? It didn't work for me. Thanks.
    It is for top level window.
    in main.cpp, just use setWindowOpacity() on the top level window you create.

  5. #5
    Join Date
    Aug 2013
    Posts
    10
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    1

    Default Re: Set transparency without setting background color

    Quote Originally Posted by aamer4yu View Post
    It is for top level window.
    in main.cpp, just use setWindowOpacity() on the top level window you create.
    I'm not using C++. It works. Thank you.

Similar Threads

  1. Less cost by setting QWidget's background color?
    By cic in forum Qt Programming
    Replies: 1
    Last Post: 11th September 2013, 10:24
  2. Setting the background color of a header in TableView
    By sunilqt in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2013, 13:06
  3. Setting Background Color
    By SixDegrees in forum Qt Programming
    Replies: 5
    Last Post: 16th February 2011, 18:33
  4. setting background color and repositioning
    By mind_freak in forum Qt Programming
    Replies: 2
    Last Post: 11th August 2009, 06:22
  5. setting background color of QMessageBox
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 23rd May 2009, 13:26

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.