Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Pressing the "Enter" key triggers unwanted response from a Button
I have an application with many Buttons, Widgets, Lables, etc...
I noticed that every time I press the Enter key - regardless of which of the many widgets has focus - it triggers the
pressed()signal associated with the "Refresh" Button you see below in the picture:
I assume it has something to do with the fact that this Button is, for some reason, surrounded with Bold frame (unlike the "Initialize Logger" Button, for example, as you can see in the pic).
- What does it mean when the Refresh Button has Bold frame?
- How do I prevent Enter key press to invoke this signal?
I thought that bold button is the one with focus, though I could be mistaken?
You don't say anything about what widget this button is on? A
QDialoghas a default button, https://doc.qt.io/qt-5/qdialog.html#default-button, is that you? If so, clear the button from being default?
See below pic of how roughly widgets are layed out.
No matter who has focus - for example - it could be some Radio Button on the uppermost QWidget that you see in the pic - the Refresh Button would still have this Bold frame around it - and Enter key will invoke it...
And you read where I wrote
A QDialog has a default button, https://doc.qt.io/qt-5/qdialog.html#default-button, is that you? If so, clear the button from being default?
and acted on unsetting the default button, right?
On that "Refresh" button I invoked setDefault(false) but it didn't help...
Not sure. To verify or eliminate this from being the issue, why don't you instead make the Initialize Logger button the default, and see if that changes what happens:
artwaw last edited by
<enter> key will always trigger default button as this is default shortcut key. Default button is usually with bold shadow on Windows - the focus is marked differently.
Please check autodefault properties of the buttons - if the buttons are in the button group, check also settings there.