On Windows 10, python3.10, PySide6 (or PyQt6) QApplication crashes when calling QPainter.drawLine() .
The terminal just displays :
Process finished with exit code -1073741819 (0xC0000005)
Please find below the code:
import sys
from PySide6.QtCore import QPoint, Qt
from PySide6.QtGui import QColor, QPainter, QPen, QPixmap
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow
# from PyQt6.QtCore import QPoint, Qt
# from PyQt6.QtGui import QColor, QPainter, QPen, QPixmap
# from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.label = QLabel()
canvas = QPixmap(400, 300)
canvas.fill(Qt.GlobalColor.white)
self.label.setPixmap(canvas)
self.setCentralWidget(self.label)
self.draw_something()
def draw_something(self):
painter = QPainter(self.label.pixmap())
painter.drawLine(10, 10, 300, 200) # >=========== Crash Here
painter.end()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()