Results 1 to 3 of 3

Thread: eventFilter and clicking inside QSpinBox

  1. #1
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default eventFilter and clicking inside QSpinBox

    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
    Qt Code:
    1. if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::FocusIn )
    To copy to clipboard, switch view to plain text mode 
    is fulfilled every time cursor stays inside, not only WHEN user placed him there FIRST time.
    Qt Code:
    1. event->type() == QEvent::MouseButtonPress
    To copy to clipboard, switch view to plain text mode 
    is true only when user clicked on spinbox arrows.
    Am I missing some events?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: eventFilter and clicking inside QSpinBox

    Most likely it's the line edit widget inside the spin box that receives those events.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2007
    Posts
    16
    Thanks
    1
    Platforms
    Windows

    Default Re: eventFilter and clicking inside QSpinBox

    "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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.