Results 1 to 6 of 6

Thread: QGraphicsItem: How block input without hack ?

  1. #1
    Join Date
    May 2013
    Posts
    304
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsItem: How block input without hack ?

    Hi,
    I actually use a hack to block input for one QGraphicsItem but I wonder if it's possible without.
    My hack is to set the item selectable and in the itemChange event set selected to false if it changed.
    Basically I only just want to block the mouse button press event because I handle the logic of this item in the scene events.
    Is it possible without this hack and have the item not selectable ? It works but the selection changed event is then called on this item...
    Thank you
    Last edited by Alundra; 1st May 2018 at 11:37.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,120
    Thanks
    235
    Thanked 656 Times in 646 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QGraphicsItem: How block input without hack ?

    What about using QGraphicsItem::setAcceptedMouseButtons() to turn off the response to the button(s)?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    May 2013
    Posts
    304
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem: How block input without hack ?

    What I need is very simple : when the mouse button is pressed this event is not propagated to things behind and not the scene too.
    Actually if you click on the item you will have the selection rectangle of the scene, I would not have that happening, just click on the item and nothing happens like a barrier of the mouse event.

  4. #4
    Join Date
    May 2013
    Posts
    304
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem: How block input without hack ?

    Found the solution :
    Qt Code:
    1. void CEditorNodeConnector::mousePressEvent( QGraphicsSceneMouseEvent* event )
    2. {
    3. QGraphicsItem::mousePressEvent( event );
    4. event->accept();
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,120
    Thanks
    235
    Thanked 656 Times in 646 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QGraphicsItem: How block input without hack ?

    Doesn't calling the base class event handler cause the unwanted effects you were trying to avoid? Or have you set the flags to make the item non-editable and non-selectable?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. #6
    Join Date
    May 2013
    Posts
    304
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem: How block input without hack ?

    Yes I removed the "selectable" flag and added this mouse filtering.
    Yes, it's true, calling the base class can be avoided.

Similar Threads

  1. Replies: 0
    Last Post: 8th April 2016, 04:34
  2. Undo/redo of multiple action slow, hack possible ?
    By Alundra in forum Qt Programming
    Replies: 6
    Last Post: 21st January 2015, 23:20
  3. Why modeless dialog block keyboard input
    By franco.amato in forum Qt Programming
    Replies: 1
    Last Post: 15th April 2010, 02:08
  4. Replies: 0
    Last Post: 2nd June 2009, 15:57
  5. QGraphicsItem and focus for key input
    By fossill in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2007, 19:13

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.