BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::WheelEventFilter Class Reference

Event filter to install on combo boxes and spin boxes to ignore wheel events during scrolling. More...

Inheritance diagram for ModelView::WheelEventFilter:
[legend]
Collaboration diagram for ModelView::WheelEventFilter:
[legend]

Public Member Functions

 WheelEventFilter (QObject *parent=nullptr)
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event)
 

Detailed Description

Event filter to install on combo boxes and spin boxes to ignore wheel events during scrolling.

Helpful than the spin box is a child of some larger scroll area.

Definition at line 41 of file customeventfilters.h.

Constructor & Destructor Documentation

◆ WheelEventFilter()

WheelEventFilter::WheelEventFilter ( QObject *  parent = nullptr)

Definition at line 34 of file customeventfilters.cpp.

34 : QObject(parent) {}

Member Function Documentation

◆ eventFilter()

bool WheelEventFilter::eventFilter ( QObject *  obj,
QEvent *  event 
)
protected

Definition at line 36 of file customeventfilters.cpp.

37 {
38  if (auto spinBox = qobject_cast<QAbstractSpinBox*>(obj); spinBox) {
39  if (event->type() == QEvent::Wheel) {
40  if (spinBox->focusPolicy() == Qt::WheelFocus) {
41  event->accept();
42  return false;
43  } else {
44  event->ignore();
45  return true;
46  }
47  } else if (event->type() == QEvent::FocusIn) {
48  spinBox->setFocusPolicy(Qt::WheelFocus);
49  } else if (event->type() == QEvent::FocusOut) {
50  spinBox->setFocusPolicy(Qt::StrongFocus);
51  }
52 
53  } else if (auto comboBox = qobject_cast<QComboBox*>(obj); comboBox) {
54  if (event->type() == QEvent::Wheel) {
55  event->ignore();
56  return true;
57  } else {
58  event->accept();
59  return false;
60  }
61  }
62  return QObject::eventFilter(obj, event);
63 }

The documentation for this class was generated from the following files: