from PyQt5.QtGui import QPixmap, QPainter # Creating a QPixmap object pixmap = QPixmap("image.png") # Creating a QPainter object painter = QPainter() # Start painting the screen painter.begin(self) # Draw the pixmap at position (100, 100) painter.drawPixmap(100, 100, pixmap) # End painting the screen painter.end()
from PyQt5.QtGui import QPixmap, QPainter class MyWidget(QWidget): def paintEvent(self, event): # Creating a QPixmap object pixmap = QPixmap("image.png") # Creating a QPainter object painter = QPainter(self) # Draw the pixmap at position (100, 100) painter.drawPixmap(100, 100, pixmap) if __name__ == "__main__": app = QApplication(sys.argv) w = MyWidget() w.show() sys.exit(app.exec_())This example uses the paintEvent() method of the QWidget class to draw an image using QPainter drawPixmap method. The image is drawn when the widget is first shown or when it is resized. Overall, these examples demonstrate how the QPainter drawPixmap method can be used to draw images in PyQt5 GUI applications. The package library used here is PyQt5.QtGui.