[PyQt] ignore click in widget in graphics scene

oliver oliver.schoenborn at gmail.com
Mon May 2 02:15:08 BST 2016


Hello, we have a QGraphicsScene that contains a qgraphicsitem that has a
qgraphicsproxywidget item with controls on it like text box and label and
scroll bars:

scene
  object frame (item)
    child 1 (item)
    child 2 (item)
    child 3 (proxy widget, item)
         panel (qwidget)
                scrollable area (qscrollablearea)
                    text box (qplaintext)
                label (qlabel)
                text box (qplaintext)

We need to prevent some of the widgets (text box etc) from capturing mouse
click events because we want the object frame (item) to handle clicks to
move the item based on mouse movement, show context menu, and respond to
double-click to open a dialog for properties of the object. However, the
scrollbars in the widget should handle mouse press/drag to move the bars
and scroll the text box.

We implemented this by deriving a class from each widget that must ignore
mouse clicks, and instantiate the derived class. For example, we have a
MyTextBox class that derives from QPlainText. Each derived class does just
one thing: override mousePressEvent() and contextMenuEvent() and make them
ignore the event.

This works, but creates many derived classes just for the purpose of
ignoring some events in widgets, and it is also easy to forget to create a
derived class (if a new type of widget is used in the proxy) or forget to
make use of an existing derived class, until client eventually reports that
moving the object (item) does not work and we find out it is because we
forget to use this technique.

Is there a better, maybe "proper" way to handle this in Qt? It would be
nice to configure scene or proxy so "all click events just go to the object
(item), except if the event was on a scrollbar".

Oliver
Open Source contributions: PyPubSub <http://pubsub.sf.net/>, nose2pytest
<https://github.com/schollii/nose2pytest>, Lua-iCxx
<http://lua-icxx.sf.net/>, iof <http://iof.sf.net/>
StackOverflow <http://stackoverflow.com/users/869951/schollii> contributions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160501/6de7646d/attachment.html>


More information about the PyQt mailing list