Results 1 to 11 of 11

Thread: Transparent widgets

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Transparent widgets

    I have read some on this subject in the forum, but for me this is still very unsure regarding implementation.

    I want my pushbutton to be like a chameleon and would have for background the zone over which it is disposed. So in fact they would look transparent.

    The the question is which function should I call to get the QPixmap occupied my the background image and give it as initial value to the widget constructor ?

    Hope you see why I try to do : use backgrounds and have transparent button disposed covering the menu labels for instance. It fills like you clicked on the baground image.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

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

    incapacitant (20th March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transparent widgets

    Does a transparent widget's class exist for pushbutton ?
    Where can I find sample code doing transparent pushbotton ?
    I this cannot grasp all of this theory and I like examples as distributed by the open source edition of QT4.1.1. They explain much of the theory.
    Anyway they should even be part of QT. It could be also handled by the QT about the background resize means.
    Last edited by incapacitant; 20th March 2006 at 20:54. Reason: additional point

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent widgets

    Did you try something like:
    Qt Code:
    1. QPalette p( button->palette() );
    2. p.setBrush( QPalette::Button, Qt::NoBrush );
    3. button->setPalette( p );
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to jacek for this useful post:

    incapacitant (20th March 2006)

  7. #5
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transparent widgets

    Qt Code:
    1. // destinataires push button
    2. pbDestin = new QPushButton( "Destinataires", this);
    3. pbDestin->resize( QSize( 80, 20 ) );
    4. pbDestin->move( 15, 90 );
    5. QPalette p( pbDestin->palette() );
    6. p.setBrush( QPalette::Button, Qt::NoBrush );
    7. pbDestin->setPalette( p );
    To copy to clipboard, switch view to plain text mode 

    This won't work. What am I doing wrong ?

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent widgets

    Quote Originally Posted by incapacitant
    This won't work.
    How does "this won't work"?

    Quote Originally Posted by incapacitant
    What am I doing wrong ?
    Well... I didn't say that it will, but you should start from the simplest solutions

  9. The following user says thank you to jacek for this useful post:

    incapacitant (20th March 2006)

  10. #7
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transparent widgets

    It shows my pushbutton + pushbutton text value + button shaPe.
    It shows nothing of the background.

    I agree we should try simplest things first.
    Last edited by incapacitant; 20th March 2006 at 21:33. Reason: spelling mistake

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent widgets

    Either this is a wrong approach or it's the QPalette bug. Try to subclass QAbstractButton and draw only text in paintEvent.

  12. The following user says thank you to jacek for this useful post:

    incapacitant (21st March 2006)

  13. #9
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transparent widgets

    Actually I would like to see nothing from my button, not even the text : 100% transparent.
    But subclassing as you propose and using paintEvent is beyond my knowledge. But thank you for helping out. I hope I can find some information about this subclassing in the QT3 book.

  14. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent widgets

    Quote Originally Posted by incapacitant
    I hope I can find some information about this subclassing in the QT3 book.
    You should rather look for a book about programming in C++.

    http://www.qtcentre.org/forum/showthread.php?t=29
    http://www.qtcentre.org/index.php?op...catid=14&id=27

    Qt Code:
    1. class Button : public QAbstractButton
    2. {
    3. public:
    4. Button( QWidget *parent = 0 ) : QAbstractButton( parent ) {}
    5. protected:
    6. void paintEvent( QPaintEvent * ) {}
    7. };
    To copy to clipboard, switch view to plain text mode 

  15. The following user says thank you to jacek for this useful post:

    incapacitant (21st March 2006)

  16. #11
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Transparent widgets

    I am more impressed by your skills than by my lack of knowledge (which is huge!!).
    Of course the piece of code you gave me works 100%.

    Thank you very much.

Similar Threads

  1. How to set Qt window transparent?
    By montylee in forum Qt Programming
    Replies: 17
    Last Post: 24th December 2013, 20:11
  2. Qt3 - Multiple transparent widgets
    By bythesea in forum Qt Programming
    Replies: 4
    Last Post: 11th September 2009, 11:24
  3. Replies: 0
    Last Post: 11th November 2008, 15:36
  4. Mac OS X Top-Level Transparent Widgets
    By tinsuke in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 16:01
  5. Transparent widgets on top of QGLWidget
    By tseval in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2007, 21:03

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.