QPushButton setFocus() not working?
-
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.
-
@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. -
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...
-
@MrShawn
Does the focus go to another widget aftereditingFinished()
(like maybe theQLineEdit
itself)? Does it work if you do this focus from elsewhere thaneditingFinished()
? At least to test, what happens if you put theui->pushButton_Process->setFocus();
into aQTimer
slot after a delay of, say, 1/10th second (so that theeditingFinished()
can complete), does that make it work?