PDA

View Full Version : Disable wheel event for a QComboBox inside a QListWidgetItem



Markus
18th March 2014, 19:32
Hello all,

I am using a QTablewidget with different widgets in different columns. The trouble begins when there are more rows to fit the view and you need to scroll. One of the columns is holding a QComboBox and when you use the scroll wheel and your mouse happens to be over a column with a QComboBox you scroll the QComboBox instead of the table view. I tried setting:

combbbox->setFocusPolicy(Qt::TabFocus);
but it does not help.

Any suggestion of how to make it react to a scroll wheel only when it already has focus?

Markus

Alundra
18th March 2014, 22:28
Why not override the mouse wheel event with event->ignore() ?

ChrisW67
18th March 2014, 22:33
I expect that reimplementing the QComboBox::wheelEvent() to look something like this would be a start (untested):


void MyComboBox::wheelEvent( QWheelEvent * e)
{
if (hasFocus())
QComboBox::wheelEvent(e);
else
e->ignore();
}

Markus
18th March 2014, 23:09
Thanks, sub-classing will work. I was wondering if there is another way.

anda_skoa
19th March 2014, 08:46
The cleaner approach is to do the override event handling in a subclass, but you can always install an event filter instead.

See QObject::eventFilter()

Cheers,
_