Disable wheel event on QDateEdit
-
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; }
-
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?
-
@Thombou
If starting out on a fair sized project using lots of widgets, I would give myself aZzLineEdit
,ZzCombBox
,ZzDateEdit
etc. (or you could put them in a namespace) directly derived fromQLineEdit
,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
QDateEdit
s, youreventFilter()
solution will do, it's only an extraif
.