问题
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