代码之家  ›  专栏  ›  技术社区  ›  Emile Victor

在Pyqt中创建QPolygon的代码正在停止我的应用程序!帮忙吗?

  •  2
  • Emile Victor  · 技术社区  · 15 年前

    大家好,

    以下代码:

    self.painter = QtGui.QPainter(self)
    self.painter.setRenderHint(QPainter.Antialiasing)
    self.painter.translate(482,395)
    self.painter.scale(300,300)
    self.painter.save()
    needle = Qt.QPolygon([QPoint(30, 0), QPoint(-30, 0), QPoint(0, 200)])
    self.painter.setBrush(Qt.cyan)
    self.painter.setPen(Qt.black)
    self.painter.drawPolygon(needle)
    self.painter.restore()
    

    导致我的Pyqt应用程序崩溃。有人知道为什么吗?它是我ui的一部分_表单.py由pyuic4自动抛出的文件。删除/注释可以解决问题。是的,这是我自己写的,而不是编译器写的。

    2 回复  |  直到 15 年前
        1
  •  2
  •   Aaron Digulla    15 年前

    保存传递给的构造函数的列表 QPolygon 在局部变量中。我猜调用一返回元素就会被垃圾回收,所以当你绘制多边形时,它们就不在周围了。

    points = [QPoint(30, 0), QPoint(-30, 0), QPoint(0, 200)]
    needle = Qt.QPolygon(points)
    
        2
  •  0
  •   Prof.Ebral Prof.Ebral    15 年前



    
    QPolygon ()
        QPolygon ( int size )
        QPolygon ( const QPolygon & polygon )
        QPolygon ( const QVector & points )
        QPolygon ( const QRect & rectangle, bool closed = false )