Results 1 to 4 of 4

Thread: interactive design

  1. #1
    Join Date
    Sep 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default interactive design

    I have a CustomItem that subclasses QGraphicsItem and draw a pie slice with

    painter->drawPie(rect, 0, 45 * 16);

    Now I want to handle the mouse click event only when the mouse is over the slice, not over the boundingRect.
    How can I do it?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: interactive design

    Implement the QGraphicsItem::contains() method for your custom item. When you receive a mouse click, check for the point using that method.

    You may not have to actually handle the mouse click - if the QGraphicsItem calls the "contains" method internally, then all you may have to do is to implement it correctly.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Sep 2016
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: interactive design

    Thanks d_stranz.
    I have found a good solution.
    If CustomItem subclasses QGraphicsEllipseItem it works perfectly.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: interactive design

    Yes, because your CustomItem class is essentially the same as a QGraphicsEllipseItem that uses a span (i.e. pie slice). Unless your custom class does something special, I don't see any need for it; just use QGraphicsEllipseItem. Notice that QGraphicsEllipseItem reimplements the contains() method...
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. pyQt with interactive SVG images
    By JeffMGreg in forum Qt Programming
    Replies: 0
    Last Post: 4th November 2011, 22:30
  2. Interactive graphics in Qt
    By wconstan in forum Newbie
    Replies: 2
    Last Post: 15th December 2010, 21:51
  3. Interactive QProcess
    By inktomi in forum Qt Programming
    Replies: 3
    Last Post: 8th August 2009, 19:21
  4. Replies: 3
    Last Post: 6th October 2008, 00:41
  5. qsqlquery interactive?
    By lamera in forum Newbie
    Replies: 2
    Last Post: 7th September 2008, 11:09

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.