Qt Application switches focus to a different application after using a file open dialog

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 12:31:56

问题


I'm porting one of my Qt apps to Windows after developing on OSX. I didn't have this problem with OSX, but it happens now under Windows 8. When I open and select a file with QFileDialog::getOpenFileName(), the focus switches to some other app and I have to alt-tab back into mine. How do I make Qt revert to the main app once the file is selected in the dialog instead of doing this?


回答1:


You probably just forgot to set the parent for the QFileDialog - you need to pass the pointer to the current window to getOpenFileName:

 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                             "",
                                             tr("Images (*.png *.xpm *.jpg)"));


来源:https://stackoverflow.com/questions/18919225/qt-application-switches-focus-to-a-different-application-after-using-a-file-open

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!