Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QWidget slots and focus
I'm a beginner with Qt and therefore have some basic questions.
I have made a very simple test program to demonstrate my issue.
If I click on the button "Set Text 1" the text "Test push button" is displayed in the lineEdit "Text1".
If I enter a text in "Text input" I copy this text into "Text Copy"
The behavior I don't understand is that when I enter a text in "Text input" and hit the enter key it fires also the pushButton slot and the text in "Text 1" is also displayed witout clicking on the button.
The related question is: Why if the focus is on Text input it remains also on the button?
Here is the code of the slots:
ui->lineEdit->setText("Test push button");
QString m_text = ui->textInput->text();
What version of Qt ?
On what OS ?
Can you show the whole code you are using ?
Maybe provide a minimal compilable example that shows the behaviour ?
Hi and thank you for taking a look at my issue or my lack of knomledge about Qt.
I'm using Qt with Windows 10
The complete test project can be downloaded from the link below
These are the information about Qt Creator.
What version of Qt are you using to build your project ?
I think its Qt 5.14.2.
How can I get this information for sure?
Yes it is Qt 5.14.2
It's defined in the Kit you are using to build your application.
mpergand last edited by
The behavior I don't understand is that when I enter a text in "Text input" and hit the enter key it fires also the pushButton slot
Because your button is the default one of the dialog.
Very common issue, see Here
I think I found a solution.
When adding a push button in the Designer, it is by default set to autoDefault.
If I uncheck this property for all push buttons I get the expected behavior