Results 1 to 4 of 4

Thread: Multiple QGraphicsEffects and subclassing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Multiple QGraphicsEffects and subclassing

    Hi,
    I need to have irregular shaped buttons that also have a QGraphicsDropShadowEffect.

    I've created a custom QGraphicsEffect which masks a widget to an irregular shape (called a maskEffect). This works fine with any QWidget.

    I've also created a custom QWidget which is basically a widget with a QPushButton inside it that is stretched to fill the widget, called myWidget. If I apply my maskEffect to the button inside myWidget and the QGraphicsDropShadowEffect to myWidget itself I have an irregular shaped button with the correct drop shadow that follows the shape of the button.

    That works because the QPushButton is mapped and the QWidget has no background so the drop shadow effect is applied to what is rendered, i.e. the masked QPushButton.

    With me so far? Good.

    The problem I'm having is I need myWidget to inherit from QPushButton and not QWidget. Since it is essentially just a QPushButton (but with an irregular shape) it should have the same functions / signals and slots etc.

    I can't see how to do this at the moment since the QPushButton is inside the QWidget. If I try to swap this round I end up losing at least one of the QGraphicsEffects.

    I imagine I would need to re-implement the paint event of QPushButton for myWidget, but then I'll still only have the outer widget to apply a single graphics effect to.

    Any ideas?

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multiple QGraphicsEffects and subclassing

    What about using QWidget::setMask() on the button to give it a shape instead of funky effect and setting the shadow using a setGraphicsEffect()?

  3. #3
    Join Date
    Feb 2010
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Multiple QGraphicsEffects and subclassing

    Thanks.

    The problem with setMask is the edges aren't anti-aliased and I couldn't work out how to do this otherwise it would seem like the best solution.

    I'm currently using a QPainterPath for the masking graphics effect, which masks the inner button and anti-aliases the edges.

    Can you use a QPainterPath with setmask?

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Multiple QGraphicsEffects and subclassing

    You can use painter path (indirectly) with set mask:
    Qt Code:
    1. QWidget::setMask( QPainterPath::toFillPolygon().toPolygon() );
    To copy to clipboard, switch view to plain text mode 

    But this will result in the same issue - edges will not be antialiased.

    As far as I know only way to have aliased edges is to draw them using QPainter.
    If you don't want to do that, maybe you could combine both effects into one shadow_and_shape effect?

Similar Threads

  1. using one signal to update multiple multiple controls
    By henryjoye in forum Qt Programming
    Replies: 7
    Last Post: 13th December 2011, 14:19
  2. Replies: 2
    Last Post: 19th October 2011, 09:30
  3. Replies: 1
    Last Post: 17th May 2011, 16:12
  4. Replies: 0
    Last Post: 21st December 2006, 11:48
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 14:06

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.