QComboBox: preventing mouse wheel without subclassing
Solved
General and Desktop
-
Is it possible disable mouse wheel event in QComboBox without subclassing and overriding wheelEvent() method?
Thanks a lot.
-
@Alexey-Serebryakov Use a eventfilter:
#include <QApplication> #include <QComboBox> #include <QPointer> #include <QWidget> class Helper: public QObject{ public: Helper(QWidget *widget): QObject(widget){ m_widget = widget; m_widget->installEventFilter(this); } bool eventFilter(QObject *watched, QEvent *event){ if(watched == m_widget && event->type() == QEvent::Wheel) return true; return QObject::eventFilter(watched, event); } private: QPointer<QWidget> m_widget; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QComboBox w; w.addItems({"item1", "item2", "item3", "item4"}); w.show(); new Helper(&w); return a.exec(); }