1.Qt鼠标悬浮Hover消息不触发,只有鼠标单击才会触发消息?
下面的工具配置,想要鼠标悬浮在工具菜单上时,显示删除的图标;但是发现怎么都触发不了
bool CBaseToolListWidget::eventFilter(QObject* ptr_object, QEvent* ptr_event){if (this == ptr_object){QEvent::Type event_type = ptr_event->type();switch (event_type){//case QEvent::Enter:case QEvent::HoverEnter:case QEvent::Move:case QEvent::HoverMove:case QEvent::MouseMove:{ DealMouseHover(Hover);}break;case QEvent::Leave:case QEvent::HoverLeave:case QEvent::DragLeave:{DealLeave();}break;case QEvent::MouseButtonDblClick:{if (isEnabled()) {DealClick(ptr_event);}}break; // case QEvent::Show: // { // DealHeight(); // } // break;case QEvent::DragMove:{DealMouseHover(DragHover);}break;default:break;}}else if (ptr_default_label_ == ptr_object){if (ptr_default_label_->isVisible()){QEvent::Type event_type = ptr_event->type();switch (event_type){case QEvent::DragEnter:case QEvent::DragMove:{ptr_default_label_->hide();}break;case QEvent::DragLeave:{DealLeave();}break;default:break;}}}return QListWidget::eventFilter(ptr_object, ptr_event);}
2.解决办法
在构造函数中加入
installEventFilter(this);
setAttribute(Qt::WA_Hover, true);//这一行会使得鼠标悬浮时,触发悬浮消息,显示删除图标的问题;