PDA

View Full Version : eventFilter and clicking inside QSpinBox



T4ng10r
6th March 2007, 18:18
I need to handle with 30 QLabels and QSpinBox stored in QGridLayout. I've created them and put in vector, after that I've placed them in proper grid cells.
Now - when user clicked inside QSpinBox (in edit field) I'm sending info to format QLabel connected with that spinbox. But

if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn )
is fulfilled every time cursor stays inside, not only WHEN user placed him there FIRST time.

event->type() == QEvent::MouseButtonPress is true only when user clicked on spinbox arrows.
Am I missing some events?

jpn
6th March 2007, 18:43
Most likely it's the line edit widget inside the spin box that receives those events.

giverson
6th March 2007, 21:02
"bool QWidget::event ( QEvent * event ) [virtual protected]

This is the main event handler; it handles event event. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.

Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent().

Mouse and tablet event handling is also slightly special: only when the widget is enabled, event() will call the specialized handlers such as mousePressEvent(); otherwise it will discard the event.

This function returns true if the event was recognized, otherwise it returns false. If the recognized event was accepted (see QEvent::accepted), any further processing such as event propagation to the parent widget stops.

Reimplemented from QObject.

See also closeEvent(), focusInEvent(), focusOutEvent(), enterEvent(), keyPressEvent(), keyReleaseEvent(), leaveEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), mousePressEvent(), mouseReleaseEvent(), moveEvent(), paintEvent(), resizeEvent(), QObject::event(), and QObject::timerEvent()."

Haven't messed with this myself but looks like enterEvent() is what you are looking for.

If not, you could always keep track of the index of your previous focus item and check to see if it matchs the index of your current focus item before doing anything.