Python - error al cargar imagen a QLabel con PySide2

 
Vista:
Imágen de perfil de lincoln
Val: 33
Ha disminuido su posición en 4 puestos en Python (en relación al último mes)
Gráfica de Python

error al cargar imagen a QLabel con PySide2

Publicado por lincoln (2 intervenciones) el 14/01/2019 23:47:50
hola amigos tengo este código:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from PySide2.QtCore import QMetaObject, QSize, QDir
from PySide2.QtWidgets import QDialog, QApplication, QPushButton, QGroupBox, QLabel, QSizePolicy, QSpacerItem, QVBoxLayout, QHBoxLayout, QGridLayout, QFileDialog
from PySide2.QtGui import QIcon, QPixmap, QImage
 
 
class Ui_Dialog(QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi()
 
 
    def setupUi(self):
        self.setObjectName("Dialog")
        self.resize(400, 300)
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setObjectName("verticalLayout")
        self.groupBox = QGroupBox(self)
        self.groupBox.setMinimumSize(QSize(0, 250))
        self.groupBox.setObjectName("groupBox")
        self.gridLayout = QGridLayout(self.groupBox)
        self.gridLayout.setObjectName("gridLayout")
        self.label = QLabel(self.groupBox)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.verticalLayout.addWidget(self.groupBox)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.pushButton = QPushButton(self)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        self.pushButton.clicked.connect(self.openFileDialog)
        self.verticalLayout.addLayout(self.horizontalLayout)
 
        self.retranslateUi(self)
        QMetaObject.connectSlotsByName(self)
 
    def retranslateUi(self, Dialog):
        self.setWindowTitle(QApplication.translate("Dialog", "Dialog", None, -1))
        self.groupBox.setTitle(QApplication.translate("Dialog", "Foto", None, -1))
        self.label.setText(QApplication.translate("Dialog", "", None, -1))
        self.pushButton.setText(QApplication.translate("Dialog", "PushButton", None, -1))
 
    def openFileDialog(self):
        fileName=QFileDialog.getOpenFileName(self,"Abrir ua imagen",QDir.rootPath(),"Imagenes (*.png *.jpg)")
        if(fileName==""):
            return
        image=QImage(fileName)
 
        self.label.setPixmap(QPixmap.fromImage(image))
        self.label.setScaledContents(True)
 
 
if __name__ == "__main__":
    import sys
    app=QApplication(sys.argv)
    d=Ui_Dialog()
    d.show()
    sys.exit(app.exec_())


la cuestión es que cuando quiero insertar la imagen ya cargada me sale este error, y la verdad o se por que, cualquier sugerencia se los agradecería, saludos.

QImage::QImage(), XPM is not supported

error
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de lincoln
Val: 33
Ha disminuido su posición en 4 puestos en Python (en relación al último mes)
Gráfica de Python

error al cargar imagen a QLabel con PySide2

Publicado por lincoln (2 intervenciones) el 15/01/2019 19:39:20
buneoya que no hay respuesta, me respondo yo solo cuando asignaba la variable fileName lo que enrealidad estaba asignando es una tupla ya que es eso lo que devuelve el QFileDialog, en tonces aqui dejo en nuevo cofigo si a alguien le sirve, suerte.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from PySide2.QtWidgets import QApplication, QDialog, QPushButton, QHBoxLayout, QVBoxLayout, QSizePolicy, QLabel, QSpacerItem, QFileDialog
from PySide2.QtGui import QPixmap
from PySide2.QtCore import QSize, QMetaObject, QDir
 
class Ui_Dialog(QDialog):
    def __init__(self):
        super().__init__()
        self.setupUi()
 
    def setupUi(self):
        self.setObjectName("Dialog")
        self.resize(400, 300)
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QLabel(self)
        self.label.setMinimumSize(QSize(0, 250))
        self.label.setText("")
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.pushButton = QPushButton(self)
        self.pushButton.setObjectName("pushButton")
        self.horizontalLayout.addWidget(self.pushButton)
        self.pushButton.clicked.connect(self.openFileDialog)
        self.label.setScaledContents(True)
        self.verticalLayout.addLayout(self.horizontalLayout)
 
        self.retranslateUi()
        QMetaObject.connectSlotsByName(self)
 
    def retranslateUi(self):
        self.setWindowTitle(QApplication.translate("Dialog", "Dialog", None, -1))
        self.pushButton.setText(QApplication.translate("Dialog", "PushButton", None, -1))
 
    def openFileDialog(self):
        fileName=QFileDialog.getOpenFileName(self,"Abrir unaimagen",QDir.homePath(),"Imagenes (*.png *.jpg *.jpeg)")
        if(fileName==""):
            return
 
        image=QPixmap(fileName[0])
        self.label.setPixmap(image)
        #self.label.setScaledContents(True)
 
        #print("Ruta de la imagen",fileName[0])
 
 
if __name__ == "__main__":
    import sys
    app=QApplication(sys.argv)
    v=Ui_Dialog()
    v.show()
    sys.exit(app.exec_())
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar