当前位置: 代码迷 >> QT开发 >> 求教各位朋友,怎么禁用鼠标事件的有关问题
  详细解决方案

求教各位朋友,怎么禁用鼠标事件的有关问题

热度:2   发布时间:2016-04-25 03:58:03.0
求教各位朋友,如何禁用鼠标事件的问题
如何能在QWT组件的qwtplot的画布里禁用滚轮事件,而在其他widget能正常使用

------解决方案--------------------
安装EventFilter
------解决方案--------------------
示例: 
class KeyPressEater : public QObject
 {
     Q_OBJECT
     ...

 protected:
     bool eventFilter(QObject *obj, QEvent *event);
 };

 bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
 {
     if (event->type() == QEvent::KeyPress) {
         QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
         qDebug("Ate key press %d", keyEvent->key());
         return true;
     } else {
         // standard event processing
         return QObject::eventFilter(obj, event);
     }
 }
And here's how to install it on two widgets:

 KeyPressEater *keyPressEater = new KeyPressEater(this);
 QPushButton *pushButton = new QPushButton(this);
 QListView *listView = new QListView(this);

 pushButton->installEventFilter(keyPressEater);
 listView->installEventFilter(keyPressEater);