Results 1 to 5 of 5

Thread: Context Menu & QGraphicsWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Context Menu & QGraphicsWidget

    First of all concerning your composite item's ::boudingRect(), you really should "think about it" My guess is to merge every child item's bounding rect.

    To ensure you computed the right boundingRect, add this code in your CompositeItem:aint() :

    Qt Code:
    1. painter->save() ;
    2. painter->setPen(Qt::yellow) ;
    3. painter->setBrush(Qt::NoBrush) ;
    4. painter->drawRect(boundinRect()) ;
    5. painter->restore() ;
    To copy to clipboard, switch view to plain text mode 

    And try to right-click on your composite item, maybe it will suffice (didn't try so I'm not sure)

  2. #2
    Join Date
    Jan 2010
    Location
    Turkey
    Posts
    39
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Context Menu & QGraphicsWidget

    You are right buddy. I think seriously about boundingRect. (I edited the code)

    Qt Code:
    1. QRectF CompositeItem::boundingRect() const
    2. {
    3. FieldItem *child;
    4. QRectF rect(0,0,0,0);
    5. foreach(child,children)
    6. {
    7. rect = rect.united(child->boundingRect());
    8. }
    9. return rect;
    10. }
    To copy to clipboard, switch view to plain text mode 

    I thinks its is a neat idea to unite child items boundingRects but this time
    item can' t catch events like contextmenuevent, mousepressevent.
    I tried to click everywhere inside boundingRect.
    What may cause this?
    Last edited by onurozcelik; 12th May 2010 at 09:05. Reason: updated contents

  3. #3
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Default Re: Context Menu & QGraphicsWidget

    sorry, I've no idea without seeing involved source code. It might come from an event you accept too early in the scene or not forwarded by a virtual method call, or even items are not selectable, etc.

  4. #4
    Join Date
    Jan 2010
    Location
    Turkey
    Posts
    39
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Context Menu & QGraphicsWidget

    I solved the problem temporarily. I rewrite paint. Now it looks as follows.

    Qt Code:
    1. void CompositeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
    2. {
    3. painter->setPen(Qt::transparent);
    4. painter->drawRect(boundingRect());
    5.  
    6. FieldItem *child;
    7. foreach(child,children)
    8. {
    9. child->paint(painter,option,widget);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Now I can catch events occurs inside rectangle
    Last edited by onurozcelik; 12th May 2010 at 12:09. Reason: spelling corrections

Similar Threads

  1. Context Menu not working
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 10th January 2010, 03:48
  2. Context menu
    By dejvis in forum Newbie
    Replies: 2
    Last Post: 20th September 2009, 22:02
  3. Qwt and context menu
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 9th December 2008, 08:55
  4. Context Menu
    By RY in forum Newbie
    Replies: 1
    Last Post: 10th September 2008, 07:59
  5. QScrollBar context menu
    By ChasW in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2007, 06:45

Tags for this Thread

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.