Results 1 to 10 of 10

Thread: setClipPath on child widgets.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Qt products
    Qt4 Qt5
    Thanks
    98
    Thanked 3 Times in 3 Posts

    Default Re: setClipPath on child widgets.

    Solution 3.
    Use QWidget::setMask. You set the mask only once, in the parent widget.
    This will apply to any subsequent painting you will do and also on the children.

    that's the solution I'd like to use, unfortunately setMask is expecting a QRegion, and my clipped area is a custom rounded rectangle path.

    Any way to create a QRegion from a QPainterPath ?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: setClipPath on child widgets.

    Try using QPainterPath::toFillPolygon() - call it with the default parameter - an identity matrix.
    For a rounded rectangle it should return exactly what you need.

    Then pass this QPolygonF to a QRegion.
    Please note that it could not look like we expect, due to the float to int conversion.
    I'm not sure yet though.

    Regards

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: setClipPath on child widgets.

    You can use QPolygonF::toPolygon to get a polygon with int coordinates.
    This should be fit to pass to a QRegion constructor.

    Regards

  4. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Qt products
    Qt4 Qt5
    Thanks
    98
    Thanked 3 Times in 3 Posts

    Default Re: setClipPath on child widgets.

    Great it seems to be working :

    Qt Code:
    1. setMask(QRegion(zePainter.DrawRoundRect(QRect(rect().x() + 2, rect().y() + 2,
    2. rect().width() - 4, rect().height() - 4),
    3. 2000 / rect().width(), 2000 / rect().height()).toFillPolygon().toPolygon()));
    To copy to clipboard, switch view to plain text mode 

    Thank you.

    Unfortunately it's a bit pixelated, Any way to apply antialiasing or a float conversion ?

    Ben.

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: setClipPath on child widgets.

    Unfortunately it's a bit pixelated, Any way to apply antialiasing or a float conversion ?
    Unfortunately you can't do anything about antialiasing when using masks.
    The float conversion can be simplified as I have shown you in my previous post.

    EDIT - I see now you already did that ( you used toPolygon ) .
    So there isn't much you can do about that either.

    Regards
    Last edited by marcel; 27th May 2007 at 18:55.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: setClipPath on child widgets.

    Is this masked widget the main widget of your app?
    If not, and if you have a normal main window, then you could use transparent png's( for example a png that contains a nice, antialiased rounded rectangle), already antialiased, instead of clippings.

    This way you can solve the antialiasing problem.

    The problem is that you cannot use transparent images on top level windows, unless your window manager supports desktop compositions.

    Currently only Vista with Aero enabled, Mac Os X, and X11 with the composite extension support it.

    Regards

Similar Threads

  1. Performance in hiding/showing widgets
    By Paalrammer in forum Newbie
    Replies: 12
    Last Post: 14th February 2007, 18:57
  2. Replies: 11
    Last Post: 7th July 2006, 13:09
  3. initialize child widgets within parent?
    By ucomesdag in forum Newbie
    Replies: 6
    Last Post: 6th June 2006, 08:11
  4. Replies: 2
    Last Post: 22nd February 2006, 14:58
  5. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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.