Unsolved QGraphicsTextItem - Accept mouse events without changing appearance
-
PySide2, Qt5:
I am catching
mousePressEvents
via inheritingQGraphicsTextItem
the following way:class TextItem(QtWidgets.QGraphicsTextItem): def mousePressEvent(self, event): print("here")
I can see print, so this works.
However, I only get the mousePressEvent called when setting
setTextInteractionFlags(QtGui.Qt.TextSelectableByMouse)
for theQGraphicsTextItem
.But this way the item gets visually activated (Text is markable and box is drawn arround). I do not want that visual change. Also, I do not want the text to be selected and copy-pasted. I just want to trigger the mouse event when the text item is clicked.
How to achieve this?
-
@MS_GX said in QGraphicsTextItem - Accept mouse events without changing appearance:
setTextInteractionFlags(QtGui.Qt.TextSelectableByMouse)
Purely at a guess. If that flag does selection which you do not want, and it can't be done some other way, then I would try looking at https://doc.qt.io/qt-5/qgraphicstextitem.html#sceneEvent for the mouse event, or possibly using https://doc.qt.io/qt-5/qgraphicstextitem.html#boundingRect to compare a scene mouse position against the rectangle of the text item?