Results 1 to 3 of 3

Thread: RubberBandDrag, mouseMoveEvent and setSelectionArea

  1. #1
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default RubberBandDrag, mouseMoveEvent and setSelectionArea

    Hi,

    I need advice - I have 2 problems I cannot solve

    I'm using QT4.5.1

    Firstly the mouseMoveEvent is not fired when drag mode is RubberBandDrag. Is this expected behavior?
    Secondly when setSelectionArea is called, the setSelected function of my QGraphicsItem is not called.

    Anyone have any ideas what i am doing wrong??
    (have I forgotten to set any flags in my scene/graphicsitems?)
    Code is below...

    Thanks for any advice


    Qt Code:
    1. // MyScene is derived from QGraphicsScene
    2.  
    3. void MyScene::mousePressEvent ( QGraphicsSceneMouseEvent * event )
    4. {
    5. views()[0]->setDragMode(QGraphicsView::RubberBandDrag);
    6. m_rubberbandP1 = event->scenePos().toPoint();
    7.  
    8. QGraphicsScene::mousePressEvent(event);
    9. }
    10.  
    11. void MyScene::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
    12. {
    13. if (views()[0]->dragMode() == QGraphicsView::RubberBandDrag)
    14. qDebug() << "mouseMoveEvent"; // never displays
    15. QGraphicsScene::mouseMoveEvent(event);
    16. }
    17.  
    18. void MyScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
    19. {
    20. views()[0]->setDragMode(QGraphicsView::ScrollHandDrag);
    21.  
    22. QRect rect(m_rubberbandP1, event->scenePos().toPoint());
    23. pp.addRect(rect);
    24. setSelectionArea(pp);
    25. QGraphicsScene::mouseReleaseEvent(event);
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: RubberBandDrag, mouseMoveEvent and setSelectionArea

    I am not able to guess what you are trying to achieve.
    If selecting items is your aim, you better have a look at the 40000 Chips demo example in Qt Demos.

    They have rubberbanding implemented there. It might help you.

  3. #3
    Join Date
    May 2009
    Posts
    63
    Thanks
    12
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: RubberBandDrag, mouseMoveEvent and setSelectionArea

    Thanks for the pointer to the example.

    I know what I was doing wrong now.

    1. I should have been overriding dragMoveEvent, not mouseMoveEvent
    2. I didn't set the ItemIsSelectable flag in the QGraphicsItem

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.