Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. widget "leave" event /"focus out" event

widget "leave" event /"focus out" event

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Monk
    wrote on last edited by
    #1

    Hello,
    [Im using QT 5.13.1 on Win 10 64bit with VS plugin 2.4.2]
    I have a groupbox containing several spinboxes. My intension is that I get a message box when groupebox losses the focus (if values in the spinboxes are changed since entering the groupbox (focus in)).
    a) Since a QGroubBox is also a QWidget and this should have the events "focus in" and "focus out" I am wondering why they are not fired.
    b) As a workaround of a) I use the "leave" event instead, but in my eventfilter I get an infinite loop of leave events and finaly a program crash. The reason is that the message box that I open causes the groupbox to fire a leave event again but the event was already fired otherwise I would not be in the eventfilter.

    bool Application::eventFilter(QObject* object, QEvent* event)
    {
    printf("event = %d\n", event->type());
    if ((object == groupbox) && (event->type() == QEvent::Leave)) // FocusOut is not fired so can't use it here
    {
    // event->accept(); // uncomment this line does not help
    // qApp->processEvents(); // uncomment this line does not help
    if (data changed)
    {
    int btn = QMessageBox::question(...);
    if (btn == QMessageBox::Ok)
    slot_roi_pb_accept();
    if (btn == QMessageBox::No)
    slot_roi_pb_cancel();
    }
    }
    return QWidget::eventFilter(object, event); // apply default filter
    }

    My questions:

    • Why does a groupebox does not fire events like "focus in" and "focus out"?
    • How can an object be left when it is already left when it is not entered in between?
    • Is there any known solution for my problem?

    BTW: The leave event is fired at the wrong time when leaving the groupebox with a pressed mouse key. It is fired when releasing the mouse key and not when leaving the area of the widget!!! Why?

    Thanks a lot

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Because there's nothing to focus on a QGroupBox. Moving the mouse over a widget won't give it focus unless you made it so.

      However, your design is a bit surprising, why not use the valueChanged signal of the QSpinBox to detect a change ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Monk
        wrote on last edited by
        #3

        Hello SGaist,
        I did not expect to have or lose focus when only moving the mouse over it but when I have the focus in a spinbos inside the groupebox and then I click somewhere outside I would expect that spinbox and all parents lose this focus.
        In my opinion a relation of objects in child parent hirachie like the controls we are talking about should behave like this. If a spinbox inside the area of a groupebox but not being a child of it (not nested) losses focus I would not expect that groupebox losses also a focus but in the case I have I expact that.

        My design is so "suprising" because I have several spinboxes and I dont want to validate each of this seperatly but at a certain time all together. In fact I have slots for all of them connected to valueChanged(int) but I do not want to get a confirm dialog for each value changed.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why would the parent lose a focus it didn't have in the first place ?

          In any case, with your additional explanations, I understand better what you want which makes it way less "surprising".

          Are all your controls grouped in group boxes ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved