0

The windows just come out empty as follows:

enter image description here

I could find this other question

  1. Why isn't the "rectangle" that I want to draw on my Qt widget showing up?

But I could not figure out how to fix mine, because he is using QWidget while I am using QGraphicsScene:

from PyQt4 import QtGui, QtCore

class MyFrame(QtGui.QGraphicsView):
    """
        Python PyQt: How can I move my widgets on the window with mouse?
        https://stackoverflow.com/questions/12213391/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_()
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144

1 Answers1

1

The problem is that it does not appear but the points that are part of the polygon are co-linear, so the polygon becomes a line. I have modified the third point to QtCore.QPointF(200, 150) showing the following:

polygon = QtGui.QPolygonF( [QtCore.QPointF( 250, 100 ), QtCore.QPointF( 400, 250 ), QtCore.QPointF( 200, 150 ) ] )

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241