Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved QFileDialog only gets auto focus on first opening

    General and Desktop
    2
    2
    474
    Loading More Posts
    • 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.
    • P
      Plank last edited by Plank

      My application contains a QFileDialog, opened by clicking a QPushButton, to open one or multiple files within the application. When the QFileDialog is opened for the very first time of the applications runtime the QFileDialog automatically gets the focus over the QMainWindow which is the wanted and expected behaviour. However if the QFileDialog is now closed and later opened again, through the exact same method, the QMainWindow keeps the focus and the user has to Alt+Tab or click the dialog to set the focus to it. Note that I open the dialog with the exec() method so it should behave as a modal dialog. I have tried messing with setFocus() and setFocusPolicy but nothing seems to affect the current behaviour. The QPushButton in question has its clicked signal connected to the following slot:

      void DataWindow::addData()
      {
          QFileDialog* dialog = new QFileDialog(this);
          dialog->setFileMode(QFileDialog::ExistingFiles);
          dialog->setNameFilter("All files (*);;");
          if (dialog->exec()) {
              // Handle selected files 
          }
          delete dialog;
      }
      

      How can I get the QFileDialog to get the focus everytime it gets opened?

      Edit: I am running Qt v5.2.1 on Ubuntu 14.04

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        You should add the version of Qt you are using as well as the OS you are running

        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 Reply Quote 0
        • First post
          Last post