I'm trying to work through the tutorial : http://www.qgistutorials.com/en/docs/building_a_python_plugin.html to build a plugin in QGIS 3.4.4. and to implement it with PyQt5 (instead of PyQt4 library in the tutorial).

after many trials, research and errors I managed to get to step 24 of the tutorial but the problem is that once I've put the push button with Qt Creator, I've added some code in "__init__" :

def __init__(self, iface):
    #for the ... button to be triggered

Then, I've added the function "select_output_file" in order to select a file to put in my dialog window :

def select_output_file(self):
    #Called when the user presses the ... button
    filename,_ = QFileDialog.getSaveFileName(self.dlg, "Select output file ","", '*.txt')

I've added an underscore ,_ as QFileDialog.getSaveFileName() returns a tuple compared to the PyQt4 version.

After many searches and trials I can't figure out how to make this button work.

  • Perhaps this post might help: QFileDialog.getSaveFileName() error in Plugin code for QGIS
    – Joseph
    Jan 25, 2019 at 15:26
  • I modified but it didn't work either
    – Brocolus
    Jan 25, 2019 at 15:38
  • What happens? Do you receive an error?
    – Joseph
    Jan 25, 2019 at 15:41
  • The problem is that it doesn't react at all, no error in QGIS or python and no window to appear even when I click on the pushbutton
    – Brocolus
    Jan 25, 2019 at 15:43
  • Put the lines you have shown from the initGui() function and place them inside the run() function then reload your plugin and try again.
    – Joseph
    Jan 25, 2019 at 15:49

1 Answer 1


Finally found out,

With QGIS 3 there's already a file selection custom widget in Qt designer. So I just took it and the used the .ui file in order to interact with the QFileDialog

In pyQGIS 3, no need to change the original "file.py" plugin file but you'll have to modify the "file_dialog.py" generated with plugin builder to interact with the Qt designer file created

If you want to succeed, the tutorial is still available for PyQt4 but for QGIS 3 and for PyQt5, you'll need to think as a PyQt5 program to make it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.