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. why setFocus does not set the focus when called on an attending pushbutton?

why setFocus does not set the focus when called on an attending pushbutton?

Scheduled Pinned Locked Moved Solved General and Desktop
setfocusdialog
9 Posts 3 Posters 673 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.
  • J Offline
    J Offline
    jdent
    wrote on 21 Mar 2024, 18:23 last edited by
    #1

    I have a pushbutton which invokes a method of a dialog. In that method I call

    setFocus(tableView)
    

    however the focus is not set in the table view!! Why? How can I set the focus to a certain widget in a dialog?

    Regards,
    Juan

    M 1 Reply Last reply 21 Mar 2024, 18:34
    0
    • J jdent
      21 Mar 2024, 19:37

      @JonB it did not work. But my tableView can accept focus: if I click on a row it is selected !! So.... what could be going on?

      J Offline
      J Offline
      JonB
      wrote on 21 Mar 2024, 19:43 last edited by
      #8

      @jdent said in why setFocus does not set the focus when called on an attending pushbutton?:

      But my tableView can accept focus: if I click on a row it is selected !!

      So far as I know, clicking a row is not focus. Why do you assume it is? Focus is for where input goes. If you want to select a row, look for select not focus in table view docs.

      J 1 Reply Last reply 21 Mar 2024, 20:08
      1
      • J jdent
        21 Mar 2024, 18:23

        I have a pushbutton which invokes a method of a dialog. In that method I call

        setFocus(tableView)
        

        however the focus is not set in the table view!! Why? How can I set the focus to a certain widget in a dialog?

        Regards,
        Juan

        M Offline
        M Offline
        mpergand
        wrote on 21 Mar 2024, 18:34 last edited by mpergand
        #2

        @jdent
        try
        tableView->setfocus();

        I already told you that:
        https://forum.qt.io/post/793573

        J 1 Reply Last reply 21 Mar 2024, 19:05
        1
        • M mpergand
          21 Mar 2024, 18:34

          @jdent
          try
          tableView->setfocus();

          I already told you that:
          https://forum.qt.io/post/793573

          J Offline
          J Offline
          jdent
          wrote on 21 Mar 2024, 19:05 last edited by
          #3

          @mpergand that's what I am doing:

          tableView->setFocus();
          

          it does not work!!

          J 1 Reply Last reply 21 Mar 2024, 19:09
          0
          • J jdent
            21 Mar 2024, 19:05

            @mpergand that's what I am doing:

            tableView->setFocus();
            

            it does not work!!

            J Offline
            J Offline
            jdent
            wrote on 21 Mar 2024, 19:09 last edited by
            #4

            @jdent maybe it cannot work because I am pressing a button and releasing will call setfocus() on the button...
            interrupting the chain of messages!!

            In MFC programming in Windows there was the concept of PostMessage() instead of SendMessage() and it was ideal for things like this. The setFocus() is like a SendMessage() but I need it to be posted in the queue of events and handled after control returns from presssing the button!! Is there nothing like this in Qt??

            J 1 Reply Last reply 21 Mar 2024, 19:13
            0
            • J jdent
              21 Mar 2024, 19:09

              @jdent maybe it cannot work because I am pressing a button and releasing will call setfocus() on the button...
              interrupting the chain of messages!!

              In MFC programming in Windows there was the concept of PostMessage() instead of SendMessage() and it was ideal for things like this. The setFocus() is like a SendMessage() but I need it to be posted in the queue of events and handled after control returns from presssing the button!! Is there nothing like this in Qt??

              J Offline
              J Offline
              JonB
              wrote on 21 Mar 2024, 19:13 last edited by JonB
              #5

              @jdent
              It is possible the pushbutton click is interfering, but I wouldn't assume so. Put your tableview->setFocus() as the action on a QTimer::singleShot() with a delay of 0 to test that. Like (untested):

              QTimer::singleShot(0, this, [this]() { tableView->setFocus(); } );
              

              It is also possible that your tableview does not accept focus? If you make your model read-only per your other thread, I don't think it will accept focus?

              J 1 Reply Last reply 21 Mar 2024, 19:37
              0
              • J JonB
                21 Mar 2024, 19:13

                @jdent
                It is possible the pushbutton click is interfering, but I wouldn't assume so. Put your tableview->setFocus() as the action on a QTimer::singleShot() with a delay of 0 to test that. Like (untested):

                QTimer::singleShot(0, this, [this]() { tableView->setFocus(); } );
                

                It is also possible that your tableview does not accept focus? If you make your model read-only per your other thread, I don't think it will accept focus?

                J Offline
                J Offline
                jdent
                wrote on 21 Mar 2024, 19:37 last edited by
                #6

                @JonB it did not work. But my tableView can accept focus: if I click on a row it is selected !! So.... what could be going on?

                J J 2 Replies Last reply 21 Mar 2024, 19:39
                0
                • J jdent
                  21 Mar 2024, 19:37

                  @JonB it did not work. But my tableView can accept focus: if I click on a row it is selected !! So.... what could be going on?

                  J Offline
                  J Offline
                  jdent
                  wrote on 21 Mar 2024, 19:39 last edited by
                  #7

                  @jdent How can I produce the signal of my mouse clicking on a row in the tableView??? Maybe I can simulate the event - trigger it!! ???

                  1 Reply Last reply
                  0
                  • J jdent
                    21 Mar 2024, 19:37

                    @JonB it did not work. But my tableView can accept focus: if I click on a row it is selected !! So.... what could be going on?

                    J Offline
                    J Offline
                    JonB
                    wrote on 21 Mar 2024, 19:43 last edited by
                    #8

                    @jdent said in why setFocus does not set the focus when called on an attending pushbutton?:

                    But my tableView can accept focus: if I click on a row it is selected !!

                    So far as I know, clicking a row is not focus. Why do you assume it is? Focus is for where input goes. If you want to select a row, look for select not focus in table view docs.

                    J 1 Reply Last reply 21 Mar 2024, 20:08
                    1
                    • J JonB
                      21 Mar 2024, 19:43

                      @jdent said in why setFocus does not set the focus when called on an attending pushbutton?:

                      But my tableView can accept focus: if I click on a row it is selected !!

                      So far as I know, clicking a row is not focus. Why do you assume it is? Focus is for where input goes. If you want to select a row, look for select not focus in table view docs.

                      J Offline
                      J Offline
                      jdent
                      wrote on 21 Mar 2024, 20:08 last edited by
                      #9

                      @JonB you are correct!! it was select I was looking for!!

                      Thanks!

                      1 Reply Last reply
                      0
                      • J jdent has marked this topic as solved on 21 Mar 2024, 20:08

                      7/9

                      21 Mar 2024, 19:39

                      • Login

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