BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
TabFromFocusProxy Class Reference

Description

Propagate tab events from focusProxy to parent.

Definition at line 101 of file CustomEventFilters.h.

Inheritance diagram for TabFromFocusProxy:
[legend]
Collaboration diagram for TabFromFocusProxy:
[legend]

Public Member Functions

 TabFromFocusProxy (QWidget *parent=nullptr)
 Passing focus-related events from child widget (e.g. QSpinBox) to parent (e.g. IntEditor) to trigger QTreeView delegate's mechanism to switch editors on "tab" press key. https://stackoverflow.com/questions/12145522/why-pressing-of-tab-key-emits-only-qeventshortcutoverride-event. More...
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event) override
 

Protected Attributes

QWidget * m_parent
 

Constructor & Destructor Documentation

◆ TabFromFocusProxy()

TabFromFocusProxy::TabFromFocusProxy ( QWidget *  parent = nullptr)

Passing focus-related events from child widget (e.g. QSpinBox) to parent (e.g. IntEditor) to trigger QTreeView delegate's mechanism to switch editors on "tab" press key. https://stackoverflow.com/questions/12145522/why-pressing-of-tab-key-emits-only-qeventshortcutoverride-event.

Definition at line 163 of file CustomEventFilters.cpp.

164  : QObject(parent)
165  , m_parent(parent)
166 {
167  if (parent->focusProxy())
168  parent->focusProxy()->installEventFilter(this);
169 }

Member Function Documentation

◆ eventFilter()

bool TabFromFocusProxy::eventFilter ( QObject *  obj,
QEvent *  event 
)
overrideprotected

Definition at line 171 of file CustomEventFilters.cpp.

172 {
173  if (event->type() == QEvent::KeyPress) {
174  auto* keyEvent = dynamic_cast<QKeyEvent*>(event);
175  if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) {
176  // we are posting event as if m_parent had "tab" key
177  QApplication::postEvent(
178  m_parent, new QKeyEvent(keyEvent->type(), keyEvent->key(), keyEvent->modifiers()));
179 
180  // but still let the origin (QSpinBox) to process it
181  return false; // process
182  }
183  }
184 
185  else if (event->type() == QEvent::FocusOut) {
186  auto* focusEvent = dynamic_cast<QFocusEvent*>(event);
187  QApplication::postEvent(this, new QFocusEvent(focusEvent->type(), focusEvent->reason()));
188 
189  // Don't filter because focus can be changed internally in editor
190  return false;
191  }
192 
193  return QObject::eventFilter(obj, event);
194 }

References m_parent.

Member Data Documentation

◆ m_parent

QWidget* TabFromFocusProxy::m_parent
protected

Definition at line 108 of file CustomEventFilters.h.

Referenced by eventFilter().


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