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. QPushButton setFocus() not working?
Forum Updated to NodeBB v4.3 + New Features

QPushButton setFocus() not working?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 993 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
    MrShawn
    wrote on last edited by
    #1

    Hey guys. Just throwing together some quick program that I am rewriting from old VB code. Trying to mirror the same functions for the users. I am shifting focus using setFocus() and selectAll() for the line edits/spin boxes (The user literally can't be bother to press tab)...

    Anyways its working fine for the line edits, spin boxes, and combo boxes, but the setFocus() is doing nothing for the push button? Any creative work arounds? I have tried next tab order.

    jsulmJ 1 Reply Last reply
    0
    • M MrShawn

      Hey guys. Just throwing together some quick program that I am rewriting from old VB code. Trying to mirror the same functions for the users. I am shifting focus using setFocus() and selectAll() for the line edits/spin boxes (The user literally can't be bother to press tab)...

      Anyways its working fine for the line edits, spin boxes, and combo boxes, but the setFocus() is doing nothing for the push button? Any creative work arounds? I have tried next tab order.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MrShawn said in QPushButton setFocus() not working?:

      Any creative work arounds?

      Don't start with work arounds before you're sure the problem is not in your code.
      Please show how you use setFocus() with QPushButton.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Not much to the code...

        void MainWindow::on_lineEdit_Operator_editingFinished()
        {
            ui->pushButton_Process->setFocus();
        
            qDebug() << focusWidget();
        }
        

        The qDebug does say it has focus but it is not highlighted and pressing enter does not click the button, unlike if I Tab over...

        JonBJ 1 Reply Last reply
        0
        • M MrShawn

          Not much to the code...

          void MainWindow::on_lineEdit_Operator_editingFinished()
          {
              ui->pushButton_Process->setFocus();
          
              qDebug() << focusWidget();
          }
          

          The qDebug does say it has focus but it is not highlighted and pressing enter does not click the button, unlike if I Tab over...

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @MrShawn
          Does the focus go to another widget after editingFinished() (like maybe the QLineEdit itself)? Does it work if you do this focus from elsewhere than editingFinished()? At least to test, what happens if you put the ui->pushButton_Process->setFocus(); into a QTimer slot after a delay of, say, 1/10th second (so that the editingFinished() can complete), does that make it work?

          1 Reply Last reply
          0

          • Login

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