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 only gets auto focus on first opening

QFileDialog only gets auto focus on first opening

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 588 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.
  • P Offline
    P Offline
    Plank
    wrote on last edited by Plank
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0

      • Login

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