Results 1 to 15 of 15

Thread: Move QGraphicsProxyWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Move QGraphicsProxyWidget

    Hi all,

    I didn't find a solution for my problem up to now:
    I have a derived class from QGraphicsProxyWidgets and want to move these in a QGraphicsScene.What I did up to now was reimplementing mousePressEvent, mouseReleaseEvent and mouseMoveEvent and called the implementations of QGraphicsItem for these events. That worked fine, but now I have a problem since I added a QPushButton in my widget which resides in the proxy widget and the mousePressEvents are not forwarded.
    So, I removed my own implementations of the mouse event handlers with the result that I can use the QPushButton normally but lost the ability to move the widgets.
    I'd like to have both.

    Any suggestions what I have to do?
    Reimplement the move functionality with itemChanged and setPos?
    Or forware mouseClicks to the widgets?

    Best regards,

    Rainer

  2. #2
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move QGraphicsProxyWidget

    Hi all,

    I found a solution. Seems a bit hackish to me, am thankful for an opinion:

    Qt Code:
    1. void ProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
    2. {
    3. QPointF pos = event->pos();
    4. QPointer<QWidget> alienWidget = widget()->childAt(pos.toPoint());
    5. if (qobject_cast<QPushButton*>(alienWidget))
    6. {
    7. QGraphicsProxyWidget::mousePressEvent(event);
    8. grabbedByWidget=true;
    9. }
    10. else
    11. {
    12. QGraphicsItem::mousePressEvent(event);
    13. grabbedByWidget=false;
    14. }
    15. }
    16.  
    17. void ProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    18. {
    19. if (grabbedByWidget)
    20. QGraphicsProxyWidget::mouseReleaseEvent(event);
    21. else
    22. QGraphicsItem::mouseReleaseEvent(event);
    23. grabbedByWidget=false;
    24. }
    25.  
    26. void ProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    27. {
    28. if (grabbedByWidget)
    29. return;
    30. QGraphicsItem::mouseMoveEvent(event);
    31. }
    To copy to clipboard, switch view to plain text mode 

    That is, I call either the implementations for the mouse event handlers of QGraphicsItem or QGraphicsProxyWidget depending on the mouse position. If I find a QPushButton under the mouse, I call the widgets handler.

    Regards,

    Rainer

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Move QGraphicsProxyWidget

    Normally a graphics item is movable if u set the flags properly. Why did you need to re implement the mouse events?

  4. #4
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move QGraphicsProxyWidget

    It is a QGraphicsProxyWidget, not a QGraphicsItem

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Move QGraphicsProxyWidget

    And isnt QGraphicsProxyWidget a descendant of QGraphicsItem

  6. #6
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move QGraphicsProxyWidget

    Yes it is. But derived classes sometimes override implementations
    QGraphicsProxyWidget has own implementations for the mouse event handlers that do not support moving it by default.
    Instead they have to care for the contained QWidget to get the mouse events.
    Last edited by RThaden; 26th February 2010 at 09:21.

  7. #7
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Move QGraphicsProxyWidget

    little suggestion ...
    add this QGraphicsProxyWidget to a QGraphicsRectItem as parent .... just like padnavigator example's roundrectitem.cpp ... u canmove the RoundRectItem ...
    "Behind every great fortune lies a crime" - Balzac

  8. The following user says thank you to wagmare for this useful post:

    RThaden (1st March 2010)

  9. #8
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move QGraphicsProxyWidget

    Thanks wagmare for this helpful suggestion. I will try that and report the results, however it will take some time, since my approach works (but smells a bit) and so the priority is a bit low at the moment.

    Best regards,

    Rainer

  10. #9
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move QGraphicsProxyWidget

    How exactly did you accomplish this? I have a similar problem, but I cant move my proxywidgets at all in the scene. Been trying all morning but with no success. So I am hoping that you can give me some pointers.

    I have also made a class deriving from QGraphicsProxyWidget but it wont allow me to pass the QGraphicsItem events

  11. #10
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Move QGraphicsProxyWidget

    meazza,

    you see my solution. I posted the code. That worked.
    I derived from QGraphicsProxyWidget and in the constructor, I did
    Qt Code:
    1. setFlag(ItemIsMovable);
    2. setFlag(ItemIsSelectable);
    To copy to clipboard, switch view to plain text mode 

    It's some time ago and I don't remember all the details.

    Regards,

    Rainer

Similar Threads

  1. help positioning QGraphicsProxyWidget?
    By Scott Shiff in forum Qt Programming
    Replies: 1
    Last Post: 24th January 2010, 23:13
  2. QGraphicsItem or QGraphicsProxyWidget?
    By ttvo in forum Qt Programming
    Replies: 5
    Last Post: 30th August 2009, 23:13
  3. QGraphicsProxyWidget
    By QbelcorT in forum Qt Programming
    Replies: 0
    Last Post: 29th November 2008, 08:21
  4. problem with QGraphicsProxyWidget
    By dreamer in forum Qt Programming
    Replies: 5
    Last Post: 19th May 2008, 22:25
  5. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.