Results 1 to 3 of 3

Thread: transparent widget

  1. #1

    Default transparent widget

    I have a little game I'm making in qt 4.1. Right now I'm doing this part while on a windows XP machine. I have a mainwindow which basicall gets created like this

    Qt Code:
    1. GUI::GUI() {
    2. // setting the max/min size
    3. setMinimumSize(350, 450);
    4. setMaximumSize(350, 450);
    5.  
    6. // filling the background with white
    7. //setAutoFillBackground(true);
    8. QPalette palette;
    9. palette.setColor(QPalette::Background, Qt::white);
    10. setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    Now when i start a new game I want to overlay like a black widget that has like a 50% transparency so you can still see the little gameboard and such. I am having no such luck getting another widget to be transparent over my mainwindow

    Here is my latest attempt at trying to get it to work

    Qt Code:
    1. QWidget *blackBG = new QWidget(this);
    2. blackBG->setGeometry(0,0,350,450);
    3. blackBG->setAutoFillBackground(true);
    4. blackBG->setPalette(QPalette(QPalette::Background, Qt::black));
    5. blackBG->setWindowOpacity(.5);
    6. blackBG->show();
    To copy to clipboard, switch view to plain text mode 

    any help? thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: transparent widget

    SetWindowOpacity only works for topLevelWindows as slightly mentioned in the docs:

    http://doc.trolltech.com/4.1/qwidget...owOpacity-prop

    They use the term window instead of widget.

    You will have to draw the semi transparent layer in the paintEvent of your widget beneath the layer.
    It's nice to be important but it's more important to be nice.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    52
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: transparent widget

    Scott Collins talked about this in his blog. Did you try this?

    http://scottcollins.net/blog/2005/10...nds-in-qt.html

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 07:06
  2. Replies: 0
    Last Post: 4th February 2009, 14:46
  3. Replies: 2
    Last Post: 19th August 2008, 09:46
  4. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  5. Transparent TextEdit or Widget
    By showhand in forum Qt Programming
    Replies: 8
    Last Post: 26th May 2006, 05:58

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.