[Tutor] Fwd: QT Python: How to re-use the return value of fileDialog.openFileName() ?

SM sunithanc at gmail.com
Tue May 28 01:25:08 CEST 2013


Thank you, for the details.


On Mon, May 27, 2013 at 10:13 AM, eryksun <eryksun at gmail.com> wrote:

> On Mon, May 27, 2013 at 9:45 AM, Matthew Ngaha <chigga101 at gmail.com>
> wrote:
> > On Mon, May 27, 2013 at 2:14 PM, SM <sunithanc at gmail.com> wrote:
> >
> >>But then I also had to use self.fileDialog from within the function. Not
> >> sure how I could avoid using fileDialog.
> >>
> >
> > No problem. to do it without the instance variable, you access its
> > method directly. so replace:
> >
> > path = self.fileDialog.getOpenFileName()
> >
> > with
> >
> > path = QFileDialog.getOpenFileName(self)
> >
> > which is basically the same thing except you're going to the method
> > directly instead of creating a class instance. The self argument may
> > or may not be needed, its been a while since ive used Qt.
>
> getOpenFileName is a static method. The first parameter is the
> [optional] parent widget. The documentation says the dialog should be
> centered over the parent, but it probably won't be if you let it use
> the default native dialog. This can be disabled with the option
> QFileDialog.DontUseNativeDialog. For example:
>
>         path = QtGui.QFileDialog.getOpenFileName(
>             parent=self,
>             caption='File Dialog',
>             directory='path/to/open',
>             filter='type1 (*.ext1);;type2 (*.ext2)',
>             selectedFilter='type2 (*.ext2)',
>             options=QFileDialog.DontUseNativeDialog,
>         )
>
> http://pyqt.sourceforge.net/Docs/PyQt4/qfiledialog.html#getOpenFileName
> http://pyqt.sourceforge.net/Docs/PyQt4/qfiledialog.html#Option-enum
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130527/fe2d5346/attachment-0001.html>


More information about the Tutor mailing list