Reputation: 997
How to open an image file with QFileDialog? I also want to know how to get the name of the file e.g. the image file is named "photo.png" and I want to print its name.
def openImage(self):
fileName = QFileDialog(self)
fileName.getOpenFileName()
image = QImage(fileName)
print(fileName.FileName)
Upvotes: 0
Views: 1790
Reputation: 997
I resolve the problem on my own:
def openImage(self):
fileName = QFileDialog().getOpenFileName()
filePath = str(fileName[0])
image = QImage(filePath)
label = QLabel()
label.setPixmap(QPixmap().fromImage(image))
self.addWidget(label, 0, 0)
fileObject = filePath.split('/')
file = fileObject[ len(fileObject) - 1 ]
print(file)
Upvotes: 1