我的应用程序有非矩形弹出窗口小部件。
他们的类定义了以下内容以实现透明性:
setAttribute(Qt::WA_NoSystemBackground, true);
setAttribute(Qt::WA_TranslucentBackground, true);
我也用:
this->setWindowFlags(Qt::Popup| Qt::FramelessWindowHint);
问题是在Windows 7上,我的窗口的底部和右侧都会绘制一个自动“阴影”。这是非常不受欢迎的。
所以,我尝试使用Qt :: Tool而不是Qt :: Popup
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
这在视觉上有效。没有阴影,但现在在我的窗口小部件窗口外单击鼠标不会像使用Qt :: Popup那样自动关闭/隐藏它。
所以,我需要这两种解决方案中的一种:
一个注意事项:我的应用程序是为Windows XP及更高版本构建的。我不能使用Vista / Win7唯一的运行时DLL,也不能使用“Windows XP”和“Vista and up”单独版本。
欢迎任何建议。
答案 0 :(得分:1)
您可以手动查看焦点何时从Qt::Tool
窗口更改。因此,基本上您可以在焦点进入流程的另一个窗口或应用程序失去焦点时进行监视。
How to detect that my application lost focus in Qt?
希望有所帮助。
答案 1 :(得分:1)
最后在意识到没有多少“SetFocusPolicy”调用允许我接收Qt :: Tool窗口的那些事件之后,我已经采取了其他措施来解决我的问题:
答案 2 :(得分:1)
我的Windows 7解决方案:
QDialog *d = new QDialog;
d->setStyleSheet("background:transparent;");
d->setAttribute(Qt::WA_DeleteOnClose, true);
d->setAttribute(Qt::WA_TranslucentBackground, true);
#ifdef Q_OS_WIN
d->createWinId();
#endif
d->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
d->show();
答案 3 :(得分:0)
我设置了QListView
d->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
安装eventfilter并使用MousePressEvent隐藏qlistview小部件。
列表上的MousePressEvent永远不会过滤它们产生我没有调试的其他事件。
因此,如果您想设计自动完成器,这将是完美的。在Qt5.3.1中测试过。