You can paint in a PyQt5 window using the QPainter widget. This widget supports adding pixels (dots) inside of the widget, unlike the other widgets. In this article we’ll explain how to use the QPainter widget with Python.
To use the widget in Qt5 we import PyQt5.QtGui. This also contains other classes like QPen and QColor.
PyQt5 QPainter example The example below paints pixels in the QPainter widget:
import sys from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel from PyQt5.QtGui import QPainter, QColor, QPen from PyQt5.QtGui import QIcon from PyQt5.QtCore import Qt import random
Leave a Reply: