Unsolved 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 theQFileDialog
is opened for the very first time of the applications runtime theQFileDialog
automatically gets the focus over theQMainWindow
which is the wanted and expected behaviour. However if theQFileDialog
is now closed and later opened again, through the exact same method, theQMainWindow
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 theexec()
method so it should behave as a modal dialog. I have tried messing withsetFocus()
andsetFocusPolicy
but nothing seems to affect the current behaviour. TheQPushButton
in question has itsclicked
signal 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
QFileDialog
to 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