Unintuitive behavior when trying to use QPushButtons default feature



  • I have designed a custom QWidget with some QPushButtons on it which I'm using as sort of a dialog window, so I'd like to be able to let the user enter things and then hit enter to click what I define as the default button. It doesn't work however and I can reproduce some pretty weird and counter-intuitive behavior in QtDesigner alone:

    I created an empty widget, pulled over a QPushButton and connected its clicked signal to the widget's close slot. Previewing the widget, everything works fine and as expected. I can also add a second button, everything still works fine. If I now put a layout on the widget, the default feature won't work anymore, meaning I can't hit enter to close the widget anymore. If I now remove the 2nd button but keep the default button in the widget layout, it goes back to working again. Wtf

    Summary:

    • no layout, 1 default button: works
    • no layout, 2 buttons (exactly 1 default button): works
    • any layout, 1 default button: works
    • any layout, multiple buttons (exactly 1 default): doesn't work

    Can anyone else reproduce this or - even better - tell me what's going on?


  • Moderators

    Hi! This works only with widgets that inherit from QDialog.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.