QFileDialog- Using getOpenFile
-
@jsulm I just did try to cancel and nothing happened, everything works fine. How to save the selected image file in database and display with the other text on the window is what i'm reading on now. Please any assistance?
@LT-K101 said in QFileDialog- Using getOpenFile:
@jsulm I just did try to cancel and nothing happened, everything works fine.
That is truly remarkable, with your existing code.
fname5, _ = QFileDialog.getOpenFileName(self, "Choose File", "", "All Files(*) ;; Images(*.jpeg)") pixmap = QPixmap(fname5, _)
So after the user clicks Cancel in the dialog, what is returned in
fname5
and most importantly what in your code stops so that it does not try to load aQPixmap
? Or do you mean it just seems to be OK when you continue ignoring the Cancel and try to load aQPixmap
from "nothing"? Try first running this and picking a suitable file to load, then re-running it and pressing Cancel, that leaves the currently loaded pixmap as-is, does it? -
@LT-K101 said in QFileDialog- Using getOpenFile:
Please any assistance?
What kind of database? SQL? https://doc.qt.io/qt-5/qtsql-index.html
-
@LT-K101 Start here: https://doc.qt.io/qt-5/qtsql-index.html
-
@LT-K101 said in QFileDialog- Using getOpenFile:
@jsulm I just did try to cancel and nothing happened, everything works fine.
That is truly remarkable, with your existing code.
fname5, _ = QFileDialog.getOpenFileName(self, "Choose File", "", "All Files(*) ;; Images(*.jpeg)") pixmap = QPixmap(fname5, _)
So after the user clicks Cancel in the dialog, what is returned in
fname5
and most importantly what in your code stops so that it does not try to load aQPixmap
? Or do you mean it just seems to be OK when you continue ignoring the Cancel and try to load aQPixmap
from "nothing"? Try first running this and picking a suitable file to load, then re-running it and pressing Cancel, that leaves the currently loaded pixmap as-is, does it? -
@LT-K101
Now I'm really lost. From theQFileDialog
clicking either Cancel or selecting a file and clicking OK should close/exit that dialog window. Originally you saidbut my application exits as soon as i click on open file
If you want help can you please state clearly whether this is still the case and/or when your application exits upon closing the file dialog.
-
@JonB I did print in the
def Load_First_Certificate(self):
function and it worked fine. I'm now using the code below to load the file as image.def Load_Second_Certificate(self): fname5, _ = QFileDialog.getOpenFileName(self, "Choose File", "", "All Files(*) ;; Images(*.jpeg)") pixmap = QPixmap(fname5, _) self.ui.Display_label_6.setPixmap(QPixmap(pixmap)) self.ui.Display_label_6.repaint()
@JonB @JonB Any help on how to display only file name instead of displaying file full path using the QFileDialog? Thanks in advance. Below is my code.
def Load_First_Certificate(self): self.fname1, ok = QFileDialog.getOpenFileName(self, "Upload Pdf File", "", "Pdf Files(*.pdf)") if ok: defaultPdf = os.path.split(self.fname1) self.ui.Pdf_lineEdit.setText(self.fname1)
-
@JonB @JonB Any help on how to display only file name instead of displaying file full path using the QFileDialog? Thanks in advance. Below is my code.
def Load_First_Certificate(self): self.fname1, ok = QFileDialog.getOpenFileName(self, "Upload Pdf File", "", "Pdf Files(*.pdf)") if ok: defaultPdf = os.path.split(self.fname1) self.ui.Pdf_lineEdit.setText(self.fname1)
-
@JonB @JonB Any help on how to display only file name instead of displaying file full path using the QFileDialog? Thanks in advance. Below is my code.
def Load_First_Certificate(self): self.fname1, ok = QFileDialog.getOpenFileName(self, "Upload Pdf File", "", "Pdf Files(*.pdf)") if ok: defaultPdf = os.path.split(self.fname1) self.ui.Pdf_lineEdit.setText(self.fname1)
print(QFile(self.fname1).fileName()) print(QFileInfo(self.fname1).fileName())
Your code:
self.fname1, ok = QFileDialog.getOpenFileName(self, "Upload Pdf File", "", "Pdf Files(*.pdf)") if ok:
Where do you get the idea that the second result is any kind of
ok
parameter, and that you should be looking at it for success? -
@JonB @JonB Any help on how to display only file name instead of displaying file full path using the QFileDialog? Thanks in advance. Below is my code.
def Load_First_Certificate(self): self.fname1, ok = QFileDialog.getOpenFileName(self, "Upload Pdf File", "", "Pdf Files(*.pdf)") if ok: defaultPdf = os.path.split(self.fname1) self.ui.Pdf_lineEdit.setText(self.fname1)
-
print(QFile(self.fname1).fileName()) print(QFileInfo(self.fname1).fileName())
Your code:
self.fname1, ok = QFileDialog.getOpenFileName(self, "Upload Pdf File", "", "Pdf Files(*.pdf)") if ok:
Where do you get the idea that the second result is any kind of
ok
parameter, and that you should be looking at it for success? -
@jsulm Thanks it's working! After selecting the pdf file saving to a location in my working directory is the problem now. Any assistance please?
@LT-K101 said in QFileDialog- Using getOpenFile:
Any assistance please?
Please ask a concrete question. What is the concrete problem you're having now?
-
@LT-K101 said in QFileDialog- Using getOpenFile:
Any assistance please?
Please ask a concrete question. What is the concrete problem you're having now?
-
@jsulm I want to save the uploaded file itself to a specific directory not just the filename. Example when the user click on open button to select file , after user select file. The file should be saved in a directory.
@LT-K101 Then do so: https://doc.qt.io/qt-5/qfile.html
-
@LT-K101 Then do so: https://doc.qt.io/qt-5/qfile.html