Segmentation Fault After Qlabel.setpixmap With Pyqt5
I'm trying to show a PIL image using QPixmap and QLabel. But when I run the code, I get SIGSEGV. Code: import sys from PIL import Image from PIL.ImageQt import ImageQt from PyQt5
Solution 1:
Try the RGBA
format:
import sys
from PIL import Image
from PIL.ImageQt import ImageQt
from PyQt5 import QtWidgets
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication, QMainWindow
classMainWindow(QMainWindow):
def__init__(self):
super().__init__()
self.setupUi(self)
# im = Image.new('RGB', (200, 200), (255, 255, 155))# im = Image.new('RGB', (500, 500), (255, 255, 255))
im = Image.new("RGBA", (500, 500), (255, 155, 155, 255)) # <---
self.label.setPixmap(QPixmap.fromImage(ImageQt(im)))
defsetupUi(self, MainWindow):
MainWindow.resize(767, 557)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.layout = QtWidgets.QGridLayout(self.centralwidget)
self.label = QtWidgets.QLabel(self.centralwidget)
self.layout.addWidget(self.label, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MainWindow()
ex.show()
sys.exit(app.exec_())
Post a Comment for "Segmentation Fault After Qlabel.setpixmap With Pyqt5"