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

Some QGraphicsItem cannot receive mouse event

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.15.2
    • PySide
    • None
    • Linux/X11

    Description

      `QGraphicsItem` created via `QGraphicsScene.addRect()` cannot receive mouse press event.

      In following code, `item1` works as expected, but `item2`'s handler will never get called.

      from PySide2.QtWidgets import (QApplication, QGraphicsRectItem, QGraphicsScene, QGraphicsView)
      
      app = QApplication()
      scene = QGraphicsScene(0, 0, 400, 400)
      
      item1 = QGraphicsRectItem(0, 0, 200, 400)
      scene.addItem(item1)
      item1.mousePressEvent = lambda event: print('#1', event)
      
      item2 = scene.addRect(200, 0, 200, 400)
      item2.mousePressEvent = lambda event: print('#2', event)
      
      view = QGraphicsView(scene)
      view.show()
      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
            cruiseliu Liu Zhe
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes