Results 1 to 7 of 7

Thread: QDialog w/ transparent background

  1. #1
    Join Date
    Jun 2006
    Location
    Arizona
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default QDialog w/ transparent background

    I know. I know.
    This question has been answered 100 times.
    I know. I know.
    I read them all.
    None of the answers work for me.
    I need a dialog with a transparent client area.
    All of my attempts have failed.
    When I attempt to mask it out, the rest (decorations) of the dialog goes gray.
    I no longer have a titlebar, frame or buttons.
    Putting a transparent label on it, only shows the background of the QDialog.
    This seems like it should be easy...
    Please help,
    TIA,
    Larry

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QDialog w/ transparent background

    Quote Originally Posted by LarryDobson View Post
    I know. I know.
    This question has been answered 100 times.
    I know. I know.
    I read them all.
    None of the answers work for me.
    Not even this? Pay attention to the parts where coordinates are being mapped from global coordinate system to widget's own coordinate system.

    I need a dialog with a transparent client area.
    Please be more specific. What is a transparent client area?

    All of my attempts have failed.
    When I attempt to mask it out, the rest (decorations) of the dialog goes gray.
    I no longer have a titlebar, frame or buttons.
    How are you applying the mask? Are you calculating a region? Or are you using QPixmap::mask()?

    Putting a transparent label on it, only shows the background of the QDialog.
    Child widgets are transparent since Qt 4.1 by default. A top level widget, however, can only be set transparent as a whole by QWidget::setWindowOpacity() (read notes in the docs), or parts of it can be made completely hidden by applying a mask. Note that any child widget intersecting a masked area becomes invisible too (over the masked area).
    J-P Nurmi

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

    LarryDobson (26th September 2006)

  4. #3
    Join Date
    Jun 2006
    Location
    Arizona
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog w/ transparent background

    Hello J-P,
    I had tried your solution.
    This left the caption bar and frame gray (with strange beveling).
    Without the ability to move or resize.
    I appreciate the help though.

    "Please be more specific. What is a transparent client area?"

    See geometry() // contents of dialog -vs- caption bar and frame

    Very close target!
    Client are is transparent, but, frame and Caption bar are gray.
    Larry

  5. #4
    Join Date
    Jun 2006
    Location
    Arizona
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Cool Re: QDialog w/ transparent background

    Got it!
    Here is the solution...

    Qt Code:
    1. void resizeEvent(QResizeEvent *e)
    2. {
    3. QDialog::resizeEvent(e);
    4.  
    5. // grab the geometry
    6. QRect fg = frameGeometry();
    7. QRect rg = geometry();
    8.  
    9. // get some reusable values
    10. int nCaptionHeight = rg.top() - fg.top();
    11. int nFrameWidth = rg.left() - fg.left();
    12.  
    13. // map the global coords to local for the frame
    14. fg.moveTo(mapFromGlobal(fg.topLeft()));
    15.  
    16. // create a rectangle for the frame
    17. QRect rectFrame(fg.left() - nFrameWidth,
    18. fg.top() - nCaptionHeight,
    19. fg.width() + ( nFrameWidth * 2 ),
    20. fg.height() + ( nCaptionHeight + nFrameWidth ) );
    21.  
    22. // create a region from the frame rectangle
    23. QRegion regionFrame( rectFrame );
    24.  
    25. // map the global coords to local for the client area
    26. rg.moveTo(mapFromGlobal(rg.topLeft()));
    27.  
    28. // move the rect to 0,0
    29. rg.moveTo( QPoint(0,0) );
    30.  
    31. // create a region from the client rect
    32. QRegion regionClient( rg );
    33.  
    34. // set a mask to be the frame region minus the client region
    35. setMask( regionFrame - regionClient );
    36. }
    To copy to clipboard, switch view to plain text mode 
    You will probably recognize some of this code from this thread.
    Many thanks to J-P Nurmi for laying the foundation...
    It just took a bit to figure out that my problem was the math (e.g. negative numbers to allow the caption bar (since QPoint(0,0) is the upper left corner of the client area).
    Thanks again JPN

    This is what I was looking for...
    Attached Images Attached Images
    Larry Dobson

    If you want to be seen... stand up
    If you want to be heard... speak up
    If you want to be respected... shut up

  6. #5
    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: QDialog w/ transparent background

    does this works with semi transparency as well?
    EDIT: after thinking about it a bit, I think it should - so:
    (in this case) QDialog gets tsetWindowOpacity() to wanted degree of opacity
    The rest as in the suggested above code.
    This way we get a semi opaque non square resizeable dialog.
    At least in theory.
    Last edited by high_flyer; 26th September 2006 at 16:43.

  7. #6
    Join Date
    Jun 2006
    Location
    Arizona
    Posts
    7
    Thanks
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDialog w/ transparent background

    Quote Originally Posted by high_flyer View Post
    does this works with semi transparency as well?
    EDIT: after thinking about it a bit, I think it should - so:
    (in this case) QDialog gets tsetWindowOpacity() to wanted degree of opacity
    The rest as in the suggested above code.
    This way we get a semi opaque non square resizeable dialog.
    At least in theory.

    In Theory...

    "non square" ??? making the dialog semi-tranparent will not effect the corners.
    Larry Dobson

    If you want to be seen... stand up
    If you want to be heard... speak up
    If you want to be respected... shut up

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QDialog w/ transparent background

    Quote Originally Posted by LarryDobson View Post
    "non square" ??? making the dialog semi-tranparent will not effect the corners.
    No, but setMask() will.

Similar Threads

  1. Replies: 3
    Last Post: 8th December 2006, 18:51
  2. Transparent background Style
    By Lele in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 12:02
  3. background colour
    By kw in forum Qt Programming
    Replies: 6
    Last Post: 11th April 2006, 00:44
  4. Replies: 1
    Last Post: 5th April 2006, 16:44
  5. Transparent widgets
    By incapacitant in forum Newbie
    Replies: 10
    Last Post: 21st March 2006, 18:01

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.