PDA

View Full Version : Pass event (QWheelEvent) to a specific widget



stefanadelbert
12th April 2010, 02:15
I have created a custom QWidget (MyWidget) which has a custom QTableView (MyTableVIew). I would like MyTableView to respond to scrolling anywhere within MyWidget (e.g. in the space around the MyTableView).

I think that when MyWidget receives a QWheelEvent I need to pass the event explicitely to MyTableView. I've tried using QApplication::sendEvent in the MyWidget::wheelEvent handler, but it's causing an infinite loop where the event keeps being passed back to MyWidget::wheelEvent.

I've tried calling wheelEvent->ignore() before calling QApplication::sendEvent, but that made no difference.

I've done some reading and it seems that I could override notify() or event() or install an eventFilter. What would be the bast and most correct way to do this? I'm probably going to want to put other special event handling in, so I should probably go for the most powerful and flexible option.

Thanks
Stefan

sloth_coder
4th May 2021, 11:42
you have to accept the event after you send the event i.e call wheelEvent->accept() after calling QApplication::sendEvent.

ChrisW67
5th May 2021, 03:10
A reply to an eleven year old post... some kind of record?