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 690 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 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
    0
    • J jdent

      @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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      1
      • J jdent

        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 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
        1
        • M mpergand

          @jdent
          try
          tableView->setfocus();

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

          J Offline
          J Offline
          jdent
          wrote on last edited by
          #3

          @mpergand that's what I am doing:

          tableView->setFocus();
          

          it does not work!!

          J 1 Reply Last reply
          0
          • J jdent

            @mpergand that's what I am doing:

            tableView->setFocus();
            

            it does not work!!

            J Offline
            J Offline
            jdent
            wrote on 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??

            JonBJ 1 Reply Last reply
            0
            • J jdent

              @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??

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on 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
              0
              • JonBJ JonB

                @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 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 JonBJ 2 Replies Last reply
                0
                • J jdent

                  @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 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

                    @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?

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on 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
                    1
                    • JonBJ JonB

                      @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 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

                      • Login

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