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. Disable wheel event on QDateEdit
Forum Updated to NodeBB v4.3 + New Features

Disable wheel event on QDateEdit

Scheduled Pinned Locked Moved Solved General and Desktop
good practice
7 Posts 3 Posters 1.0k 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.
  • T Offline
    T Offline
    Thombou
    wrote on last edited by Thombou
    #1

    Hi,
    I want to disable the wheel event on all QDateEdit of my application. What is the best between subclassing Qdate edit and installing a global filter on the entire app?

    My code for the global event filter is the following and it works but I am not sure it is the most efficient way of doing it.

    bool MainWindow::eventFilter(QObject* target, QEvent *e)
    {
        if (qobject_cast<QDateEdit*>(target)!=NULL && e->type() == QEvent::Wheel){
            return true;
        }
        return false;
    }
    
    1 Reply Last reply
    0
    • eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #2

      @Thombou use the QLineEdit of QDateEdit: https://doc.qt.io/qt-5/qabstractspinbox.html#lineEdit

      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
      1
      • T Offline
        T Offline
        Thombou
        wrote on last edited by
        #3

        Hi! Thanks for your answer.
        What do you mean? Subclassing QDateEdit, then getting the spinbox and filter the wheel event on the spinbox?

        JonBJ 1 Reply Last reply
        0
        • T Thombou

          Hi! Thanks for your answer.
          What do you mean? Subclassing QDateEdit, then getting the spinbox and filter the wheel event on the spinbox?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Thombou
          Yes, that is the neater way, but requires you to subclass all your existing QDateEdits. If you start out subclassing all widgets you use it's easy. If you don't want to change your code then your original code seems fine.

          1 Reply Last reply
          1
          • T Offline
            T Offline
            Thombou
            wrote on last edited by
            #5

            Thanks for the advice!
            Small follow up question.

            @JonB said in Disable wheel event on QDateEdit:

            If you start out subclassing all widgets you use it's easy

            You mean that it's agood practice to subclass all kind of widgets I use? I did not know that. Is it how you do it?

            JonBJ 1 Reply Last reply
            0
            • T Thombou

              Thanks for the advice!
              Small follow up question.

              @JonB said in Disable wheel event on QDateEdit:

              If you start out subclassing all widgets you use it's easy

              You mean that it's agood practice to subclass all kind of widgets I use? I did not know that. Is it how you do it?

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Thombou
              If starting out on a fair sized project using lots of widgets, I would give myself a ZzLineEdit, ZzCombBox, ZzDateEdit etc. (or you could put them in a namespace) directly derived from QLineEdit, QCombBox, QDateEdit, and use those for all the widgets I create. It's only a couple of lines of code done once. You never know when you might discover you need to add something in the subclass it for some reason....

              But in your case if you don't want to go hunt down all your existing QDateEdits, your eventFilter() solution will do, it's only an extra if.

              1 Reply Last reply
              1
              • T Offline
                T Offline
                Thombou
                wrote on last edited by Thombou
                #7

                @JonB Thank you! It always good to know some good practice. It is something I miss a bit... If you have any recommendation where I could find more tips like this, let me know!

                1 Reply Last reply
                0

                • Login

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