使用事件过滤器来实现
protected:
bool eventFilter(QObject *o, QEvent *e);//事件过滤器
bool chatEmotion::eventFilter(QObject *o , QEvent *e)
{
if(QEvent::WindowDeactivate == e->type())//窗口停用
{
hide();//或者关闭窗口
}
else return QWidget::eventFilter(o , e);
}
最好别忘了在构造函数里面安装事件过滤器。
installEventFilter(this);
本文介绍了一种使用事件过滤器的方法,通过在窗口停用时隐藏或关闭窗口来实现特定功能。文章提供了具体的代码示例,并强调了在构造函数中安装事件过滤器的重要性。
459

被折叠的 条评论
为什么被折叠?



