Я хочу нарисовать несколько линий и точек с помощью PySide2, и я выполнил документацию и предоставил код ниже, но он ничего не показывает после вызова функции.
class Window2(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Deformed Structure")
self.DrawWindows = QtGui.QWindow()
self.DrawButton23 = QPushButton('Draw', self)
self.DrawButton23.setStyleSheet("Background-color: orange")
self.DrawButton23.move(100, 200)
self.DrawButton23.show()
self.DrawButton23.clicked.connect(self.PaintEvent)
def PaintEvent(self, painter):
painter = QtGui.QPainter()
painter.begin(self)
pen = QPen(Qt.green)
painter.setPen(pen)
for i in range(0, 10):
x0 = i * 30
y0 = i * 30
x1 = 100 + i * 50
y1 = 100 + i * 50
point1 = QPointF(x0, y0)
point2 = QPointF(x1, y1)
line1 = QLineF(point1, point2)
painter.drawPoint(point1)
painter.drawLine(line1)
print("OK123") #Just to check the loop, it prints 10 time
painter.end()