显示/隐藏 QMenu
Show/Hide of QMenu
我通过继承QMenu
创建了"开始"菜单。我想使用滑动样式的QPropertyAnimation
显示和隐藏它
问题:
当我显式调用它们时,显示和隐藏工作正常(单击开始按钮)。但是当我在开始菜单之外单击时,它会立即隐藏。请告诉我这背后可能是什么原因:
My class is StartMenuUiClass which inherited from QMenu
mptrobj_animation is QPropertyAnimation object
void StartMenuUiClass::show()
{
this->raise();
disconnect(mptrobj_animation,SIGNAL(finished()),this,SLOT(this_hide()));
QMenu::show();
mptrobj_animation->setDuration(500);
mptrobj_animation->setStartValue(*mptrobj_startPosition);
mptrobj_animation->setEndValue(*mptrobj_endPosition);
mptrobj_animation->start();
}
void StartMenuUiClass::hide()
{
mptrobj_animation->setDuration(450);
mptrobj_animation->setStartValue(*mptrobj_endPosition);
mptrobj_animation->setEndValue(*mptrobj_startPosition);
connect(mptrobj_animation,SIGNAL(finished()),this,SLOT(this_hide()));
mptrobj_animation->start();
}
void StartMenuUiClass::this_hide()
{
this->lower();
emit work_Done();
QMenu::hide();
}
我认为
,如果您在菜单小部件外部单击,它只会隐藏或关闭,而不涉及您的StartMenuUiClass::hide()
功能。您可以尝试处理QMenu::hideEvent(QHideEvent *event)
和/或QWidget::closeEvent(QCloseEvent *event)
。像这样:
StartMenuUiClass::closeEvent(QCloseEvent *event) // the same for hideEvent()
{
this->hide();
event->accept();
}
相关文章:
- 这是我尝试让用户将值输入到数组中.然后将其隐藏为大量的星号
- 结构和双指针隐藏在其他结构中,多层混淆
- 在 cpp 文件中隐藏采用模板参数引用的方法
- 参数包构造函数在类模板中隐藏用户定义的转换
- 如何等待窗口隐藏在Qt中?
- 如何使用类型别名从模板化类中隐藏模板列表
- 在设计 SDK 时,我是否应该在 C++ 头文件中完全隐藏内部类?
- 名称隐藏对静态函数继承的实例使用
- 在 Linux 中使用 ioctl() 获取隐藏功能报告时,零字节消失
- 从多个模板化基类派生时出现"隐藏重载的虚函数"警告
- 如何在 Omnet++ 5.6.1 中隐藏箭头?
- 在C++中隐藏键盘记录器的控制台窗口
- 从静态库使用时隐藏不透明结构的内容
- 隐藏用于聚合初始化的空基类
- 使用智能指针指向 C 库中的结构,该结构通过 typedef 隐藏实现(即不完整的类型)
- Qt中的包装连接方法隐藏了编译器所需的信息
- 隐藏重载虚拟功能的模板化访客:SFINAE 在使用?
- 在 ui 文件中隐藏 QTabWidget 中的单个选项卡窗格?
- 显示/隐藏 QMenu
- Q工具栏切换显示隐藏在Qmenu上