Is there a ready-made widget in qt so that a picture from the file is set in it?
1 answer
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel from PyQt5.QtGui import QPixmap class App(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle('Тест') self.setGeometry(200, 200, 300, 300) def load_image(self, file_name): pixmap = QPixmap(file_name) self.label = QLabel(self) self.label.setPixmap(pixmap) self.label.resize(pixmap.width(), pixmap.height()) self.resize(pixmap.width(), pixmap.height()) if __name__ == '__main__': import sys app = QApplication(sys.argv) ex = App() ex.load_image('image.jpg') ex.show() sys.exit(app.exec_()) |
QLabelwith HTML markup in thetextproperty:<img src="file:///путь_к_картинке" />. - ߊߚߤߘ