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

Propagate tab events from focusProxy to parent. More...

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

Public Member Functions

 TabFromFocusProxy (QWidget *parent=0)
 Passing focus-related events from child widget (e.g. More...
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event)
 

Protected Attributes

QWidget * m_parent
 

Detailed Description

Propagate tab events from focusProxy to parent.

Definition at line 97 of file CustomEventFilters.h.

Constructor & Destructor Documentation

◆ TabFromFocusProxy()

TabFromFocusProxy::TabFromFocusProxy ( QWidget *  parent = 0)

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 153 of file CustomEventFilters.cpp.

153  : QObject(parent), m_parent(parent)
154 {
155  if (parent->focusProxy())
156  parent->focusProxy()->installEventFilter(this);
157 }

Member Function Documentation

◆ eventFilter()

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

Definition at line 159 of file CustomEventFilters.cpp.

160 {
161  if (event->type() == QEvent::KeyPress) {
162  QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
163  if (keyEvent->key() == Qt::Key_Tab || keyEvent->key() == Qt::Key_Backtab) {
164  // we are posting event as if m_parent had "tab" key
165  QApplication::postEvent(
166  m_parent, new QKeyEvent(keyEvent->type(), keyEvent->key(), keyEvent->modifiers()));
167 
168  // but still let the origin (QSpinBox) to process it
169  return false; // process
170  }
171  }
172 
173  else if (event->type() == QEvent::FocusOut) {
174  QFocusEvent* focusEvent = static_cast<QFocusEvent*>(event);
175  QApplication::postEvent(this, new QFocusEvent(focusEvent->type(), focusEvent->reason()));
176 
177  // Don't filter because focus can be changed internally in editor
178  return false;
179  }
180 
181  return QObject::eventFilter(obj, event);
182 }

References m_parent.

Member Data Documentation

◆ m_parent

QWidget* TabFromFocusProxy::m_parent
protected

Definition at line 104 of file CustomEventFilters.h.

Referenced by eventFilter().


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