Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-2774

Can't get .setMouseTracking(True) working without holding mouse button down

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.7.1
    • PySide
    • None
    • Windows 10
      VSCode
    • Windows

    Description

      So far with testing .setMouseTracking(True) not able to get it working when used in conjuction with mouseMoveEvent().

      It only works when the mouse button is held down over the widget.

      Maybe I'm missing something

      Please help.

      Python 3.10

      Here is my basic example

      from PySide6.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
      from PySide6.QtGui import QMouseEvent
      import sys

      class MyWidget(QWidget):
          def {}init{}(self):
              super().{}init{}()
              self.setMouseTracking(True)
              self.label = QLabel("Move the mouse inside the window")
              layout = QVBoxLayout()
              layout.addWidget(self.label)
              self.setLayout(layout)

          def mouseMoveEvent(self, event: QMouseEvent):
              position = event.position()  # Use position() instead of pos()
              self.label.setText(f"Mouse moved to: {position.x(){color:#569cd6}}, {position.y(){color:#569cd6}}")
              event.accept()

      if {}name{} == "{}main{}":
          app = QApplication(sys.argv)
          widget = MyWidget()
          widget.resize(400, 300)
          widget.show()
          sys.exit(app.exec())

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            robochop Greg Crawford
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes