I have been working my way through Summerfields book on Rapid GUI programming with Python and QT (PyQt to be more precise), but the book from 2007 uses version 4.x and I am trying to get going with the current version (5.4.2).
There are some changes that I am trying to figure out and would love some assistance on how to find stuff. Here is an example for a file save dialog - from the book:
fname = QFileDialog.getSaveFileName(self,
"Image Changer - Save Image", fname,
"Image files ({})".format(" ".join(formats)))
This does not work, perhaps primarily because in PyQt5 the QFileDialog
returns a tuple rather than a string. The only way I can figure this out is just by trial and error. The PyQt5 documentation refers you to QT, which I really do not understand.
I got the following to work:
fname = QFileDialog.getSaveFileName(self, 'some text',
"whatever.png", '*.png')
if "." not in fname[0]:
fname[0] += ".png"
self.addRecentFile(fname[0])
self.filename = fname[0]
return self.fileSave()
Wow, it works! But it is just by slogging through that I get any progress. I tried running python interpreter and typed:
from PyQt5.QtWidgets import QFileDialog
help(QFileDialog)
This is (sort of) helpful, but the syntax of the help does not make a lot of sense to me, and I do not see what getSaveFileName
is supposed to return.
What am I missing?