Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Opening the File Manager when a Push Button is clicked
Forum Updated to NodeBB v4.3 + New Features

Opening the File Manager when a Push Button is clicked

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nwaara4
    wrote on last edited by nwaara4
    #1

    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++.

    Thanks,
    Nick

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      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).

      N 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        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).

        N Offline
        N Offline
        nwaara4
        wrote on last edited by
        #3

        @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!

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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
          
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved