Qt应用程序在使用文件打开对话框后将焦点移动到不同的应用程序 [英] Qt Application switches focus to a different application after using a file open dialog

查看:675
本文介绍了Qt应用程序在使用文件打开对话框后将焦点移动到不同的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OSX上开发后,我正在将我的一个Qt应用程序移植到Windows。我没有这个问题与OSX,但它发生在Windows 8下。当我打开并选择一个文件与 QFileDialog :: getOpenFileName(),焦点切换到一些其他的应用程序和我不得不alt-tab回我的。

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?

推荐答案

如果我们在对话框中选择了文件,只是忘记为 QFileDialog 设置 parent - 您需要将指针传递到当前窗口 getOpenFileName

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)"));

这篇关于Qt应用程序在使用文件打开对话框后将焦点移动到不同的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆