Important: Please read the Qt Code of Conduct -

Opening the File Manager when a Push Button is clicked

  • Hello,
    This seems like a very simple task in my head but I've spent the past day searching a trying to figure out the right way to do this and I can't seem to find anything that works. All that I want to do is have a push button in my gui that when clicked, opens up the file manager so that the user can look through all of their files and select the proper one. If anyone knows of a way that I can do this I would really appreciate the help! If you have any questions about what I'm trying to figure out just let me know. Also it has to be in python, not c++.


  • Moderators

    Hi, welcome to devnet.

    It's as easy as calling one of the static methods of QFileDialog:

    QString path = QFileDialog::getOpenFileName();
    if(!path.isEmpty()) { //empty path means user canceled the dialog
        // do something with the path

    If you want to customize the dialog more, e.g. give it a meaningful caption or select only files with specific extension take a look at the linked docs for the description of parameters you can pass. There's also a method for multiple files and directories.

    As for it being in Python, I can't help you with that but I'm sure it's just a minor syntax difference (like a dot instead of :: etc).

  • @Chris-Kawa that is what I've been trying but everything gives me errors. Also I need it in python (or PyQt) not in C++. I've tried doing it a lot of different ways but no matter what I seem to do it doesn't want to work... If you could try to clarify more or give me a python example I would appreciate it!

  • Moderators

    Well I never coded a single line of Python in my life but according to PyQt docs this is the way to do it (the . instead of :: as I said):

    path = QtGui.QFileDialog.getOpenFileName()
    if path:
       # do something with the path

Log in to reply