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. [Solved] "Lock" the UI while waiting on an async event?
QtWS25 Last Chance

[Solved] "Lock" the UI while waiting on an async event?

Scheduled Pinned Locked Moved General and Desktop
22 Posts 4 Posters 17.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.
  • R Offline
    R Offline
    reactive
    wrote on 18 Mar 2011, 14:45 last edited by
    #5

    My event filter is on another machine but is essentially:
    @
    qapp->installEventFilter(this)

    eventFilter(...){

    if(event.type == mouse press|release|dblclick or key press)
    return true
    else
    return false

    }
    @

    The weird thing (aside from the random failure to consume a button signal) is that if I click
    in text fields it moves the cursor between them - though it does at least always consume
    key presses. How is the cursor bouncing around if the mouse events are consumed?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on 18 Mar 2011, 14:54 last edited by
      #6

      Never forget to call the base implementation if you don't handle an event yourself.

      I am not saying that will fix your issue though.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZapB
        wrote on 18 Mar 2011, 14:58 last edited by
        #7

        I think they will be getting translated to FocusInEvent's somewhere earlier in the chain.

        Try setting a break point in your event filter to see what object/event combinations are being accepted. You can then add to the list of combinations that you need to filter out.

        Nokia Certified Qt Specialist
        Interested in hearing about Qt related work

        1 Reply Last reply
        0
        • R Offline
          R Offline
          reactive
          wrote on 18 Mar 2011, 15:00 last edited by
          #8

          Thanks Andre. I did see that in the QObject::installEventFilter documentation where they use "return QObject::eventFilter(obj, evt)", but I wasn't sure if I should call that or qapp.eventFilter(obj, evt)?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 18 Mar 2011, 15:04 last edited by
            #9

            No, always call on your own base class. It may have it's own event filters installed, and these need to get processed as well.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              reactive
              wrote on 18 Mar 2011, 15:29 last edited by
              #10

              I am printing out the event types and in the cases where the button is firing I'm seeing a 200 event type (CloseSoftwareInputPanel). I should say - if I just put the mouse over the button and click away, the filter works as expected. These "randomly" successful button clicks is when I alternate quickly between a text field and the button while pressing a key repeatedly.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                ZapB
                wrote on 18 Mar 2011, 15:31 last edited by
                #11

                I am not sure what that event means or how it is triggered :-)

                However, since you have identified it just consume it and you should get what you need.

                Nokia Certified Qt Specialist
                Interested in hearing about Qt related work

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  reactive
                  wrote on 18 Mar 2011, 15:36 last edited by
                  #12

                  Gah! That didn't work. It seems that moving the mouse to the text edit component right above the button and then back down and clicking is sufficient to outsmart the filter. :(

                  EDIT: I figured out the cause! Clicking on the button and not releasing and then moving the mouse outside the button. I don't even have to release the mouse button. Just moving it outside fires the signal. Now to fix it...

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on 18 Mar 2011, 15:41 last edited by
                    #13

                    Wouldn't it make sense to simply disable all controls if you don't want them active?

                    Otherwise, you might look into invoking blockSignals() on your button. That should stop it from emitting any signal.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on 18 Mar 2011, 15:44 last edited by
                      #14

                      locking the widgets is one thing (perhaps just disable main window?)
                      what about close event etc? Are this also disabled then?

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        reactive
                        wrote on 18 Mar 2011, 15:54 last edited by
                        #15

                        Unfortunately it's not a trivial GUI with just a couple of static widgets. There are many nested pieces full of widgets that change with time. Many user actions must wait on a server response message that could take (uncomfortably) many seconds to come back. I really didn't want to blank out the screen or display a modal "waiting..." dialog for that long, but I would like to defend against impatient mouse clickers and button mashers.

                        I'm new to Qt so I have no idea what the best way to do this. I'm only trying the eventFilter way because that's the response I got. blockSignals() sounds good but I'd have to traverse the whole layout tree and do it on everything which doesnt sound appealing.

                        Gerolf, what did you mean by "disabling" the main window?

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andre
                          wrote on 18 Mar 2011, 16:00 last edited by
                          #16

                          Well, applying it to all buttons at least should be easy enough:

                          @
                          //mainWindow is a pointer to the widget that represents your ui widget

                          QList<QAbstractButton*> buttons = mainWindow.findChildren<QAbstractButton*>();
                          foreach(QAbstractButton* button, buttons)
                          button->blockSignals(true);
                          @

                          I think Gerolf was talking about this:
                          @
                          mainWindows->setEnabled(false);
                          @

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            reactive
                            wrote on 18 Mar 2011, 16:07 last edited by
                            #17

                            SON OF A...! :)
                            mainWindow->setEnabled(false) was EXACTLY what I was looking for. Thanks so much.

                            Going back to that "glitch" for a moment, is that behavior a bug?
                            Clicking on a button without release and then moving outside the button while still
                            holding the button down, should not fire. In fact, in most cases isn't this exactly how
                            you cancel an accidental press.
                            I've never seen that type of behavior on any platform.

                            1 Reply Last reply
                            0
                            • A Offline
                              A Offline
                              andre
                              wrote on 18 Mar 2011, 16:13 last edited by
                              #18

                              OK, that's good. I marked the issue as "Solved".

                              I hope you did notice that the setEnabled() call also modifies the visual appearance of your application? I hope that is what you intended? Personally, I like it when I can see that clicking won't have an effect, but that wasn't too clear from your use case.

                              I think Qt normally won't fire a clicked() signal if you move the mouse off a button before releasing. If it does, I would considder that a bug, but perhaps it was caused by your own event filter (blocking a focus out, perhaps?)

                              1 Reply Last reply
                              0
                              • Z Offline
                                Z Offline
                                ZapB
                                wrote on 18 Mar 2011, 16:14 last edited by
                                #19

                                Apologies, I thought that you wanted the widgets left enabled otherwise I would have suggested that. My bad.

                                Nokia Certified Qt Specialist
                                Interested in hearing about Qt related work

                                1 Reply Last reply
                                0
                                • R Offline
                                  R Offline
                                  reactive
                                  wrote on 18 Mar 2011, 16:27 last edited by
                                  #20

                                  modifies the visual appearance of your application

                                  TBH, I wanted to block for X seconds without a different visual appearance, and then
                                  after a timeout then go to the disabled look. I'm not going to be choosy though!
                                  The eventFilter() solution was almost perfect, but reliable code is more important.

                                  Apparently, that unwanted button behavior happens when you consume mouse press and
                                  mouse release (but not either alone). Another mark against the eventFilter method is that
                                  if you right-click in a text box and popup displays that locks up the app for good.

                                  Apologies... My bad

                                  No way. Thanks for the help. It would have been a great solution without that one hiccup.

                                  1 Reply Last reply
                                  0
                                  • Z Offline
                                    Z Offline
                                    ZapB
                                    wrote on 18 Mar 2011, 16:38 last edited by
                                    #21

                                    You also have to block QEvent::ContextMenu event types to stop context menus appearing.

                                    So can you only consume MousePress but not MouseRelease?

                                    Nokia Certified Qt Specialist
                                    Interested in hearing about Qt related work

                                    1 Reply Last reply
                                    0
                                    • R Offline
                                      R Offline
                                      reactive
                                      wrote on 18 Mar 2011, 16:45 last edited by
                                      #22

                                      So can you only consume MousePress but not MouseRelease?

                                      Well, the text box cursors move on mouse presses and the popup menu appears
                                      on mouse release (in a text box) - so somehow text boxes are getting around
                                      the mouse event filter.

                                      I can't even guess at the button behavior, but it must somehow still knows you're clicking on it too.

                                      1 Reply Last reply
                                      0

                                      14/22

                                      18 Mar 2011, 15:44

                                      • Login

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