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. QFileDialog - enter key behaviour

QFileDialog - enter key behaviour

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.5k Views
  • 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.
  • R Offline
    R Offline
    rivierakid
    wrote on last edited by
    #1

    Hi, here is a directory chooser code:
    @QFileDialog dlg(this);
    dlg.setFileMode(QFileDialog::Directory);
    dlg.setOptions(QFileDialog::ShowDirsOnly);
    dlg.setAcceptMode(QFileDialog::AcceptSave);
    dlg.exec();@

    The problem is the keyboard-enter behaviour: when user type a dir using keyboard and press enter, it immediately calls accept().
    But I prefer to show the content of given dir when the directory-lineEdit has a focus - without closing the dialog...

    Is there any way to change keyboard-enter behaviour?

    Thanks.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      d2uriel
      wrote on last edited by
      #2

      Without looking in the docs I guess you'd have to subclass QFileDialog and change it's keyPressEvent().

      "Do not judge, and you will never be mistaken." - Jean-Jacques Rousseau

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        One thing you can do is check whether the dialog input is a valid directory. If not, pop the dialog again...

        You don't really need to instantiate a QFileDialog object, you can simply do something like this:
        @
        QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home", QFileDialog::ShowDirsOnly);@

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rivierakid
          wrote on last edited by
          #4

          yes, i know that native dialog works, but it is not so beautiful as styled Qt dialog :o)
          The problem is with network path - typically the user types a machine name: \computer\ and then he wants to pick the dir...

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #5

            Well, you can always write your own custom input dialog it is fairly easy, or subclass QFileDialog and modify it.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rivierakid
              wrote on last edited by
              #6

              Ok, that's the way.
              But I think that the default behaviour of the qt-style dialog si buggy, because no one wants to choose dir with enter when the edit line is focused...

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #7

                Ironically, the native dialog is working very well for me, I can type folder names, press enter and pretty much navigate everywhere, ugly - maybe, but I am more about functional anyway :)

                If you really think it is a bug you can always "file a bug report":http://bugreports.qt.nokia.com/ :)

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rivierakid
                  wrote on last edited by
                  #8

                  For now, I have switched to native dialog too :)

                  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