QFileDialog only gets auto focus on first opening
-
My application contains a
QFileDialog, opened by clicking aQPushButton, to open one or multiple files within the application. When theQFileDialogis opened for the very first time of the applications runtime theQFileDialogautomatically gets the focus over theQMainWindowwhich is the wanted and expected behaviour. However if theQFileDialogis now closed and later opened again, through the exact same method, theQMainWindowkeeps 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 theexec()method so it should behave as a modal dialog. I have tried messing withsetFocus()andsetFocusPolicybut nothing seems to affect the current behaviour. TheQPushButtonin question has itsclickedsignal connected to the followingslot: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
QFileDialogto get the focus everytime it gets opened?Edit: I am running Qt v5.2.1 on Ubuntu 14.04
-
Hi and welcome to devnet,
You should add the version of Qt you are using as well as the OS you are running