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

QGraphicsItem调用update不生效

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.3.1
    • PySide
    • None
    • Windows
    • 测试代码有问题

    Description

      QGraphicsLine调用update时,并不会更新界面。在C++代码中测试是可以的。

      python代码如下:

      from PySide6 import QtCore,QtWidgets,QtGui
      
      class UiScene(QtWidgets.QGraphicsScene):
          u'画图'
      
          def __init__(self,parent=None):
              super().__init__(parent)
              self.setStickyFocus(True)
      
              self.currentItem = None
      
          def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
              print("mouse press")
              pos = event.scenePos()
              self.currentItem = self.addLine(QtCore.QLine(pos.x(),pos.y(),1,1),QtGui.QPen(QtCore.Qt.red))        
              return super().mousePressEvent(event)
      
          def mouseReleaseEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
              return super().mouseReleaseEvent(event)
      
          def mouseMoveEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
              pos = event.scenePos()
              if self.currentItem:
                  line = self.currentItem.line()
                  line.setP2(event.pos())
                  self.currentItem.setLine(line)
                  self.currentItem.update()
                  self.update()
              return super().mouseMoveEvent(event)
      

      Attachments

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

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            turner.gao turner.gao
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes