Results 1 to 5 of 5

Thread: Disabling ItemIsSelectable for all objects in the graphics scene?

  1. #1
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Disabling ItemIsSelectable for all objects in the graphics scene?

    In my QGraphicsScene, I put selectable QGraphicsItems in my class. My scene has multiple modes, one of which follows standard selecting behavior. Other modes include a way for the user to paint items.

    The other modes don't call QGraphicsScene::mousePressEvent, QGraphicsScene::mouseMoveEvent and QGraphicsScene::mouseReleaseEvent. Yet still, if I double-click an existing item, it is marked as selected.

    Any idea as to why this might happen? For a split second I thought about marking every item in the scene as unselectable when the user switches to a non-select mode, but that's a ridiculous workaround and I'm sure that you know how to tackle this quirk properly.

  2. #2
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Disabling ItemIsSelectable for all objects in the graphics scene?

    Your view propagates mouse clicks directly to the items,therefore they become selected.Thats why disabling mouse events for the scene does not work.
    Last edited by MasterBLB; 1st May 2011 at 09:49.

  3. #3
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disabling ItemIsSelectable for all objects in the graphics scene?

    Aha, that explains a lot... can I easily override this behavior? Or do I have to create my own specialization of a QGraphicsView and override the mouse click events?

  4. #4
    Join Date
    Sep 2008
    Location
    Poland
    Posts
    80
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Disabling ItemIsSelectable for all objects in the graphics scene?

    It depends what you want to archieve.If your view does not have to respond at all to mouse clicks then you may instal an event filter on it.But if it does,then you have options:
    1.Set appropriate flag on each item (what you want to avoid as I can understand).Thats the option if you're using Qt's graphics items without subclassing them.
    2.If you use own items,then you may override mousePressEvent and mouseDoubleClickEvent.You may check inside the state of your scene,and then accept/reject the event

    btw-that 'aha' phrase makes me suspicous if you are from Poland?Because I'm Polish,and if it isn't forbidden we may write in Polish.

  5. #5
    Join Date
    Nov 2010
    Posts
    77
    Thanks
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disabling ItemIsSelectable for all objects in the graphics scene?

    Quote Originally Posted by MasterBLB View Post
    It depends what you want to archieve.If your view does not have to respond at all to mouse clicks then you may instal an event filter on it.
    I have to catch all graphics view clicks, so that isn't an option.

    Quote Originally Posted by MasterBLB View Post
    2.If you use own items,then you may override mousePressEvent and mouseDoubleClickEvent.You may check inside the state of your scene,and then accept/reject the event
    I think this is the best solution to my problem. I'll subclass the graphics view and override these events. I have one question though... I use Qt Creator's GUI designer, so I can't just use my subclassed QGraphicsView, can I? Is there a way to do this properly?

    Quote Originally Posted by MasterBLB View Post
    btw-that 'aha' phrase makes me suspicous if you are from Poland?Because I'm Polish,and if it isn't forbidden we may write in Polish.
    Sorry to disappoint you, but I'm not. 'Aha' is a pretty universal word: http://en.wiktionary.org/wiki/Aha

Similar Threads

  1. generate XML file from the Graphics Scene
    By sajis997 in forum Newbie
    Replies: 3
    Last Post: 13th April 2011, 15:14
  2. Using QLayout for layout in a graphics scene
    By ticica in forum Qt Programming
    Replies: 1
    Last Post: 21st November 2009, 04:07
  3. graphics scene
    By dognzhe in forum Qt Programming
    Replies: 3
    Last Post: 3rd June 2009, 08:55
  4. Buttons in Graphics Scene
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2007, 19:24
  5. QTreeWidget and Graphics scene
    By aamer4yu in forum Qt Programming
    Replies: 7
    Last Post: 21st December 2006, 17:24

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.