import sys from PySide2.QtWidgets import QApplication, QMainWindow, QWidget from PySide2.QtGui import QPainter, QPen from PySide2.QtCore import Qt class MyWidget(QWidget): def paintEvent(self, event): painter = QPainter(self) pen = QPen(Qt.red) pen.setWidth(2) painter.setPen(pen) painter.drawLine(0, 0, self.width(), self.height()) app = QApplication(sys.argv) window = QMainWindow() widget = MyWidget() window.setCentralWidget(widget) window.show() sys.exit(app.exec_())This code creates a simple PySide2.QtGui application with a custom widget that draws a red line with a width of 2 pixels from the top-left corner to the bottom-right corner of the widget. Package library: PySide2.QtGui.