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. Sequence of show() and setFocus()
Forum Updated to NodeBB v4.3 + New Features

Sequence of show() and setFocus()

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 5.1k Views 3 Watching
  • 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #1

    Hi

    Is it correct that show() on a widget does not also move the Focus to it?
    If yes, I have to set the Focus manually with setFocus().
    Does the sequence of these need to follow a rule?
    Can I set Focus on a widget that is not yet shown or is the other way round correct?

    I need to send keys to widgets (I'm using QApplication::sendEvent) and make sure they go there.

    Thanks
    McL

    raven-worxR 1 Reply Last reply
    0
    • McLionM McLion

      Hi

      Is it correct that show() on a widget does not also move the Focus to it?
      If yes, I have to set the Focus manually with setFocus().
      Does the sequence of these need to follow a rule?
      Can I set Focus on a widget that is not yet shown or is the other way round correct?

      I need to send keys to widgets (I'm using QApplication::sendEvent) and make sure they go there.

      Thanks
      McL

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @McLion
      first show() then setFocus()
      Invisible and disabled widgets can't receive focus and thus no input events.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      McLionM 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @McLion
        first show() then setFocus()
        Invisible and disabled widgets can't receive focus and thus no input events.

        McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        @raven-worx
        OK, thanks ... that's actually what I was thinking.
        However, the question came up because I read here: http://doc.qt.io/qt-4.8/focus.html
        At the bottom it says:
        ... call QWidget::setFocus() on the widget which should receive focus before you call QWidget::show() it.
        which then would not make sense ... or do I mix some things here?

        raven-worxR 1 Reply Last reply
        0
        • McLionM McLion

          @raven-worx
          OK, thanks ... that's actually what I was thinking.
          However, the question came up because I read here: http://doc.qt.io/qt-4.8/focus.html
          At the bottom it says:
          ... call QWidget::setFocus() on the widget which should receive focus before you call QWidget::show() it.
          which then would not make sense ... or do I mix some things here?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @McLion said in Sequence of show() and setFocus():

          At the bottom it says:
          ... call QWidget::setFocus() on the widget which should receive focus before you call QWidget::show() it.
          which then would not make sense ... or do I mix some things here?

          If you leave out the first part of the sentence it indeed is contrary to what i said ;)

          What happens is that every window (top-level) QWidget stores it's focus widget to restore it upon show/window-activation.
          So when there has never been a focus before, and you set it on a widget which is already a (grand-)child of the window before it is shown, the window stores it and then restores it when it is shown.

          But still it wouldn't receive input event, because it's not visible.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          McLionM 1 Reply Last reply
          1
          • raven-worxR raven-worx

            @McLion said in Sequence of show() and setFocus():

            At the bottom it says:
            ... call QWidget::setFocus() on the widget which should receive focus before you call QWidget::show() it.
            which then would not make sense ... or do I mix some things here?

            If you leave out the first part of the sentence it indeed is contrary to what i said ;)

            What happens is that every window (top-level) QWidget stores it's focus widget to restore it upon show/window-activation.
            So when there has never been a focus before, and you set it on a widget which is already a (grand-)child of the window before it is shown, the window stores it and then restores it when it is shown.

            But still it wouldn't receive input event, because it's not visible.

            McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by
            #5

            @raven-worx
            Thanks for the 'clear-up'.

            1 Reply Last reply
            1
            • McLionM Offline
              McLionM Offline
              McLion
              wrote on last edited by
              #6

              ... where have the tools gone to set as solved ?

              raven-worxR 1 Reply Last reply
              0
              • McLionM McLion

                ... where have the tools gone to set as solved ?

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #7

                @McLion said in Sequence of show() and setFocus():

                ... where have the tools gone to set as solved ?

                a bit hidden:
                "TOPIC TOOLS" in the very bottom right -> select "Ask a question"
                Then open the menu up again and the "mark as solved" option is there

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                McLionM 1 Reply Last reply
                1
                • raven-worxR raven-worx

                  @McLion said in Sequence of show() and setFocus():

                  ... where have the tools gone to set as solved ?

                  a bit hidden:
                  "TOPIC TOOLS" in the very bottom right -> select "Ask a question"
                  Then open the menu up again and the "mark as solved" option is there

                  McLionM Offline
                  McLionM Offline
                  McLion
                  wrote on last edited by
                  #8

                  @raven-worx said in Sequence of show() and setFocus():

                  @McLion said in Sequence of show() and setFocus():

                  ... where have the tools gone to set as solved ?
                  

                  a bit hidden:
                  "TOPIC TOOLS" in the very bottom right -> select "Ask a question"
                  Then open the menu up again and the "mark as solved" option is there

                  Jeeez ... who designed this !?!

                  mrjjM 1 Reply Last reply
                  0
                  • McLionM McLion

                    @raven-worx said in Sequence of show() and setFocus():

                    @McLion said in Sequence of show() and setFocus():

                    ... where have the tools gone to set as solved ?
                    

                    a bit hidden:
                    "TOPIC TOOLS" in the very bottom right -> select "Ask a question"
                    Then open the menu up again and the "mark as solved" option is there

                    Jeeez ... who designed this !?!

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    @McLion said in Sequence of show() and setFocus():

                    Jeeez ... who designed this !?!

                    People that wanted to make forum software that could be used with other use cases.
                    Sadly, here we always mean it as a Question but its not default.
                    So why not remove it?
                    Well when you start to customize something as big as Qt forum then you get heaps of issue upgrading it to a newer version to get security patches.
                    Hence it was chosen to use the software as plain as possible.
                    So while not perfect for our use case, the drawbacks is outweighed by huge factor by the benefit of not
                    having to spend weeks to see if the old adjustments still works.
                    So that is why :)

                    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