hola amigos tengo este codigo:
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.
Código:
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_())
QImage::QImage(), XPM is not supported