Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox: preventing mouse wheel without subclassing
Forum Updated to NodeBB v4.3 + New Features

QComboBox: preventing mouse wheel without subclassing

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 349 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexey Serebryakov
    wrote on last edited by Alexey Serebryakov
    #1

    Is it possible disable mouse wheel event in QComboBox without subclassing and overriding wheelEvent() method?

    Thanks a lot.

    eyllanescE 1 Reply Last reply
    0
    • A Alexey Serebryakov

      Is it possible disable mouse wheel event in QComboBox without subclassing and overriding wheelEvent() method?

      Thanks a lot.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

      @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();
      }
      

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      4

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved