Results 1 to 2 of 2

Thread: How to enable rubber band selection in QGraphicsView even if clicked on an item?

  1. #1
    Join Date
    Jan 2012
    Posts
    66
    Thanks
    20
    Thanked 2 Times in 2 Posts
    Platforms
    Windows

    Default How to enable rubber band selection in QGraphicsView even if clicked on an item?

    I have a QGraphicsScene/View with QGraphicsItems that accept mouse events (e.g., to move or resize them). I'd like to be able to Ctrl-click the QGraphicsView to enable the rubber band selection even if the initial click location is centered on one of these items.

    I know how to check whether or not Ctrl was held down in the QGraphicsItem's mousePressEvent (using "if (event->modifiers().testFlag(Qt::ControlModifier))"), but not what to do with this condition. Perhaps the QGraphicsItem is the wrong place to test this condition?

    Of course, QGraphicsView seems the logical place, but from what I recall, it automatically disables rubber band selection if the click location is centered on an item that accepts mouse clicks.

  2. #2
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to enable rubber band selection in QGraphicsView even if clicked on an item?

    Qt Code:
    1. class MyItem : public QGraphicsItem
    2. {
    3. public:
    4. MyItem() {}
    5.  
    6. protected:
    7. void mousePressEvent( QGraphicsSceneMouseEvent* event )
    8. {
    9. if( event->modifiers() & Qt::CTRL ) // you know that
    10. {
    11. event->ignore(); // and that's all you need to know :)
    12. }
    13. }
    14. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Conditional rubber band selection in QGraphicsView
    By stevel in forum Qt Programming
    Replies: 5
    Last Post: 14th January 2011, 08:32
  2. How do I clear the rubber band after a selection is done
    By aarelovich in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2010, 12:29
  3. QRubberband- Mouse clicked on Rubber band area
    By bismitapadhy in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2010, 08:10
  4. How to draw rubber band using XOR
    By lni in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2009, 12:13
  5. Rubber band artifacts?
    By mooreaa in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2008, 18:19

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.