I'm building a QGIS plugin which only requires user interaction to select a save location for an output file. I used Plugin Builder to create a template and assumed I could simply replace the template dialog with a QFileDialog object. Here's the relevant code:
def run(self): """Run method that performs all the real work""" # Create the dialog with elements (after translation) and keep reference # Only create GUI ONCE in callback, so that it will only load when the plugin is started if self.first_start == True: self.first_start = False self.dlg = QFileDialog(self.iface) self.dlg.setFileMode(QFileDialog.AnyFile) self.dlg.setNameFilter(self.tr("Zip files (*.zip)")) # self.dlg = GiftWrapDialog() # show the dialog self.dlg.show() # Run the dialog event loop result = self.dlg.exec_() # See if OK was pressed if result: # Do something useful here - delete the line containing pass and # substitute with your code. pass
This code throws an error when I try to run the plugin:
TypeError: arguments did not match any overloaded call: QFileDialog(QWidget, Union[Qt.WindowFlags, Qt.WindowType]): argument 1 has unexpected type 'QgisInterface' QFileDialog(parent: QWidget = None, caption: str = '', directory: str = '', filter: str = ''): argument 1 has unexpected type 'QgisInterface'
Is there any way for my plugin to simply show a standard file dialog without having to create my own dialog?