from PyQt4 import QtGui # Create a QGraphicsScene object scene = QtGui.QGraphicsScene() # Create a QGraphicsLineItem object and add it to the scene line = QtGui.QGraphicsLineItem(0,0,100,100) scene.addItem(line) # Create a QGraphicsView object and set the scene on it view = QtGui.QGraphicsView(scene) # Show the view view.show()
from PyQt4 import QtGui, QtCore # Create a QGraphicsScene object scene = QtGui.QGraphicsScene() # Create a QGraphicsLineItem object and add it to the scene line = QtGui.QGraphicsLineItem(0,0,100,100) scene.addItem(line) # Change the pen color of the line pen = QtGui.QPen(QtCore.Qt.red, 5) line.setPen(pen) # Create a QGraphicsView object and set the scene on it view = QtGui.QGraphicsView(scene) # Show the view view.show()In this example, we create a QGraphicsScene object and a QGraphicsLineItem object, and add the line item to the scene. We then change the pen color of the line to red with a line width of 5. We create a QGraphicsView object and set the scene on it, and finally show the view.