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:

    c0c9b3e8-2993-4b21-b9a2-59574a76fd98-image.png

    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).

    1. What does it mean when the Refresh Button has Bold frame?
    2. How do I prevent Enter key press to invoke this signal?

    Thanks



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



  • 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...

    4d34cbac-c732-46d8-b388-93ec141ca243-image.png



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



  • I did.
    On that "Refresh" button I invoked setDefault(false) but it didn't help...



  • @Absurd
    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:

    self.btnInitializeLogger.setDefault(true);
    


  • Hi,
    <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.


Log in to reply