Results 1 to 11 of 11

Thread: Transparent Qwidget

  1. #1

    Default Transparent Qwidget

    Hi all,

    Is it possible to make a QWidget showed (by invoking .show()) with transparent background?

    I've read some related articles in the forum, and had tried some methods including:
    1. setAttribute(Qt::WA_NoSystemBackground)
    2. setStyleSheet("background-color: transparent")
    3. In paintEvent: QPixmap pix(size()); pix.fill(Qt::transparent); painter.drawPixmap(0,0,pix);

    But no one succeed, I tested above methods within Shaped Clock example (which is under QTDIR/examples/widgets/shapedclock). Under Windows XP, I got a black background, and under Ubuntu 8.10, i got a vague background.

    Any sugguestion or help are welcomed, keep waiting online!

  2. #2
    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: Transparent Qwidget

    If you want whole of your window to be transparent, you can use QWidget::setWindowOpacity .

    It is difficult if u want transparent background and semi-transparent/opaque child widgets.
    For that you can refer this thread

  3. #3

    Default Re: Transparent Qwidget

    Thanks for your message!
    We don't want to make full transparent of the widget, just the background.

    Actually, our final destination is to make the background of a WebView widget showed with transparent background, so that we can render some shaped contents on desktop. Somehow like Yahoo! widget effects. Is that possible via Qt?

    Sorry for not making my point clear enough.

  4. #4
    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: Transparent Qwidget

    I guess you want to draw/write on desktop.
    For that you can take snap of desktop, save it on pixmap, and render this pixmap as background .
    You can find related examples in the forum.
    Also search for shaped clock example, alpha widget example(on qt labs i guess).

    This might also help you

  5. #5

    Default Re: Transparent Qwidget

    Wow, that looks great, i will have a try, many thanks in advance!

  6. #6

    Default Re: Transparent Qwidget

    Quote Originally Posted by aamer4yu View Post
    I guess you want to draw/write on desktop.
    For that you can take snap of desktop, save it on pixmap, and render this pixmap as background .
    You can find related examples in the forum.
    Also search for shaped clock example, alpha widget example(on qt labs i guess).

    This might also help you
    I ran this sample code at here

    But it's weird that there shows a transparent window with nothing in it, i expected there should be a sentence of "Qt Centre" on the label, btw, my Qt version is 4.5.0-beta1, is this the reason for this problem?

  7. #7

    Default Re: Transparent Qwidget

    My god, the sample works well on Windows... frameless... only label text shown on screen...
    Totally confused! Anything more to be noticed under X11? Btw, i'm using Ubuntu 8.10 now.

    Thanks in adv!
    Last edited by naruto_9w; 13th January 2009 at 13:52.

  8. #8
    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: Transparent Qwidget

    I dont know about X11, but u can see ARGB window in Trolltech labs --> dojo examples.

  9. #9

    Default Re: Transparent Qwidget

    Quote Originally Posted by aamer4yu View Post
    I dont know about X11, but u can see ARGB window in Trolltech labs --> dojo examples.
    Thank your clue very much!

    Anyone else can offer some tips for this issue? Thx

  10. #10

    Default Re: Transparent Qwidget

    After rebuilding Qt4.5 beta, the sample code works, and it also does in Qt4.4.3.
    However the dojo ARGB demo still render black background...

  11. #11
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Transparent Qwidget

    On Ubuntu, you might need to have a composite window manager enabled (such as Compiz/Beryl/Metacity Composite).

    Otherwise you'll get a black background, and setMask() would be your only best bet.

Similar Threads

  1. QWidget inside QGroupbox semi transparent [Qt 4.3.1]
    By desch in forum Qt Programming
    Replies: 7
    Last Post: 26th February 2009, 10:00
  2. Replies: 0
    Last Post: 11th November 2008, 15:36
  3. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  4. Transparent background on QLabel on transparent QWidget
    By codeslicer in forum Qt Programming
    Replies: 1
    Last Post: 13th February 2008, 02:10
  5. Transparent QWidget on QGLWidget
    By showhand in forum Qt Programming
    Replies: 2
    Last Post: 27th November 2006, 01:00

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.