为什么 QPoligonF 对象没有出现在我的 pyqt4 QGraphicsScene 上?
Why the QPoligonF object is not showing up on my QGraphicsScene at pyqt4?
刚出来的windows空的如下:
我可以找到另一个问题
- Why isn't the "rectangle" that I want to draw on my Qt widget showing up?
但我不知道如何修复我的,因为他在使用 QWidget
而我在使用 QGraphicsScene
:
from PyQt4 import QtGui, QtCore
class MyFrame(QtGui.QGraphicsView):
"""
Python PyQt: How can I move my widgets on the window with mouse?
"""
def __init__( self, parent = None ):
super( MyFrame, self ).__init__( parent )
scene = QtGui.QGraphicsScene()
self.setScene( scene )
self.resize( 400, 240 )
# http://pyqt.sourceforge.net/Docs/PyQt4/qpen.html
pencil = QtGui.QPen( QtCore.Qt.black, 2)
pencil.setStyle( QtCore.Qt.SolidLine )
polygon = QtGui.QPolygonF( [ QtCore.QPointF( 250, 100 ), QtCore.QPointF( 400, 250 ), QtCore.QPointF( 300, 150 ) ] )
brush = QtGui.QBrush( QtGui.QColor( 125, 125, 125, 125 ) )
scene.addPolygon( polygon, pencil, brush )
if ( __name__ == '__main__' ):
app = QtGui.QApplication( [] )
f = MyFrame()
f.show()
app.exec_()
问题是它没有出现,但是作为多边形一部分的点是共线的,所以多边形变成了一条线。我已将第三点修改为 QtCore.QPointF(200, 150)
,显示如下:
polygon = QtGui.QPolygonF( [QtCore.QPointF( 250, 100 ), QtCore.QPointF( 400, 250 ), QtCore.QPointF( 200, 150 ) ] )
刚出来的windows空的如下:
我可以找到另一个问题
- Why isn't the "rectangle" that I want to draw on my Qt widget showing up?
但我不知道如何修复我的,因为他在使用 QWidget
而我在使用 QGraphicsScene
:
from PyQt4 import QtGui, QtCore
class MyFrame(QtGui.QGraphicsView):
"""
Python PyQt: How can I move my widgets on the window with mouse?
"""
def __init__( self, parent = None ):
super( MyFrame, self ).__init__( parent )
scene = QtGui.QGraphicsScene()
self.setScene( scene )
self.resize( 400, 240 )
# http://pyqt.sourceforge.net/Docs/PyQt4/qpen.html
pencil = QtGui.QPen( QtCore.Qt.black, 2)
pencil.setStyle( QtCore.Qt.SolidLine )
polygon = QtGui.QPolygonF( [ QtCore.QPointF( 250, 100 ), QtCore.QPointF( 400, 250 ), QtCore.QPointF( 300, 150 ) ] )
brush = QtGui.QBrush( QtGui.QColor( 125, 125, 125, 125 ) )
scene.addPolygon( polygon, pencil, brush )
if ( __name__ == '__main__' ):
app = QtGui.QApplication( [] )
f = MyFrame()
f.show()
app.exec_()
问题是它没有出现,但是作为多边形一部分的点是共线的,所以多边形变成了一条线。我已将第三点修改为 QtCore.QPointF(200, 150)
,显示如下:
polygon = QtGui.QPolygonF( [QtCore.QPointF( 250, 100 ), QtCore.QPointF( 400, 250 ), QtCore.QPointF( 200, 150 ) ] )