Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsTextItem - Accept mouse events without changing appearance
Forum Updated to NodeBB v4.3 + New Features

QGraphicsTextItem - Accept mouse events without changing appearance

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 270 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MS_GX
    wrote on last edited by
    #1

    PySide2, Qt5:

    I am catching mousePressEvents via inheriting QGraphicsTextItem 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 the QGraphicsTextItem.

    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?

    JonBJ 1 Reply Last reply
    0
    • M MS_GX

      PySide2, Qt5:

      I am catching mousePressEvents via inheriting QGraphicsTextItem 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 the QGraphicsTextItem.

      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?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved