Results 1 to 7 of 7

Thread: QDialog w/ transparent background

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

  2. #2
    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.

  3. #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

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,372
    Thanks
    3
    Thanked 5,019 Times in 4,795 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
  •  
Qt is a trademark of The Qt Company.