Results 1 to 8 of 8

Thread: Redirecting mouse events from a QGraphicsView to a QGraphicsScene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Redirecting mouse events from a QGraphicsView to a QGraphicsScene

    Quote Originally Posted by blooglet View Post
    So the poster is wrong?
    You can judge that yourself based on the code I provided.

    Then what is the correct way to prevent items from being selected in a QGraphicsScene if my graphics scene is in a state where I don't want the user to be able to select items?
    The correct way is to remove the ItemIsSelectable flag from the items. Another good way is to not call the base class implementation of mouse events in the scene but then you lose not only selection but also other features such as focus and item moving.

    I override the default implementation of QGraphicsScene::mousePressEvent, QGraphicsScene::mouseMoveEvent and QGraphicsScene::mouseReleaseEvent when the scene is in a non-select state and I don't call the base class implementation. Still, I'm able to select items that have QGraphicsItem::ItemIsSelectable enabled by double-clicking them.
    Apparently you are doing something wrong. My guess is you didn't override mouseDoubleClickEvent.
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class GraphicsScene : public QGraphicsScene {
    4. public:
    5. GraphicsScene() : QGraphicsScene(){}
    6. protected:
    7. void mousePressEvent(QGraphicsSceneMouseEvent *e) {
    8.  
    9. }
    10. void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e){}
    11. };
    12.  
    13. int main(int argc, char **argv){
    14. QApplication app(argc, argv);
    15. GraphicsScene scene;
    16. view.setScene(&scene);
    17. QGraphicsEllipseItem *item = scene.addEllipse(QRect(0,0,100,50), QPen(Qt::red), Qt::blue);
    18. item->setFlag(QGraphicsItem::ItemIsSelectable);
    19. view.show();
    20. return app.exec();
    21. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    blooglet (22nd May 2011)

Similar Threads

  1. QGraphicsView mouse events
    By high_flyer in forum Qt Programming
    Replies: 22
    Last Post: 29th May 2014, 09:03
  2. Replies: 5
    Last Post: 27th April 2010, 11:04
  3. how to connect events with signals in QGraphicsScene?
    By nataly in forum Qt Programming
    Replies: 0
    Last Post: 3rd November 2009, 15:20
  4. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

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.