Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Disable "Open" button when no file is selected in QFileDialog

Disable "Open" button when no file is selected in QFileDialog

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 853 Views 1 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.
  • F Offline
    F Offline
    fvez_demtroys
    wrote on last edited by
    #1

    Hi,

    We are making an internal configuration tool using PyQt5 5.15.4.
    Development is done on macOS Catalina 10.15.7
    The final version will run on both OSX and Windows 10

    On Windows 10, when you open a QFileDialog, the "Open" button is enabled even when no file is selected.
    Here is an image to illustrate the issue.

    Is there a way to change this behaviour?
    For example, on MacOS, the button is disabled as long as no file is selected.
    Would it be possible to have the same behaviour on Windows 10?

    Thanks,
    FVez

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How are you invoking that dialog ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F fvez_demtroys

        Hi,

        We are making an internal configuration tool using PyQt5 5.15.4.
        Development is done on macOS Catalina 10.15.7
        The final version will run on both OSX and Windows 10

        On Windows 10, when you open a QFileDialog, the "Open" button is enabled even when no file is selected.
        Here is an image to illustrate the issue.

        Is there a way to change this behaviour?
        For example, on MacOS, the button is disabled as long as no file is selected.
        Would it be possible to have the same behaviour on Windows 10?

        Thanks,
        FVez

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by JonB
        #3

        @fvez_demtroys
        Are you aware that this is actually the normal behaviour of this Windows "Open" dialog, e.g. cf. from Notepad? I had never noticed and agree I don't know why, but given it's the standard Windows behaviour do you really want to bother to try changing it?

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fvez_demtroys
          wrote on last edited by fvez_demtroys
          #4

          @SGaist I invoke the dialog with

          QFileDialog.getOpenFileName(caption='Open .txt', filter="Text Files (*.txt)")
          

          @JonB Yes I did see that this seemed like standard behaviour on Windows.
          I was wondering if QFileDialog had a way of disabling the open button as long as no file is selected.
          I don't necessarily want to change it manually, seems like a lot of work for very little gain.
          I added safety checks on the string obtained by getOpenFileName, this way if no file is selected it shouldn't cause issues.

          Thanks!
          FVez

          JonBJ 1 Reply Last reply
          0
          • F fvez_demtroys

            @SGaist I invoke the dialog with

            QFileDialog.getOpenFileName(caption='Open .txt', filter="Text Files (*.txt)")
            

            @JonB Yes I did see that this seemed like standard behaviour on Windows.
            I was wondering if QFileDialog had a way of disabling the open button as long as no file is selected.
            I don't necessarily want to change it manually, seems like a lot of work for very little gain.
            I added safety checks on the string obtained by getOpenFileName, this way if no file is selected it shouldn't cause issues.

            Thanks!
            FVez

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @fvez_demtroys said in Disable "Open" button when no file is selected in QFileDialog:

            I was wondering if QFileDialog had a way of disabling the open button as long as no file is selected.

            I'm not sure, but I don't think so. You are using the native Windows dialog here, not the Qt-rolled alternative one. That means it looks and functions under the windowing system's control, I believe.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @JonB is correct, the default is to use the native file dialogs which means follow the platform style for interaction.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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