Question

I've been developing a desktop application using Qt Creator under Linux (Kubuntu). Under linux, all is well, but under Windows, in a dialog box, the wrong button is selected by default when the window appears.

There are three buttons: Edit, Continue and Stop.

Continue is marked as 'AutoDefault' and 'Default'.

Stop is marked as 'AutoDefault', but not 'Deafault'.

Edit is marked as neither 'AutoDefault' nor 'Default', but when the dialog opens, it is selected, and pressing enter presses the Edit button.

The source for the program can be found at https://github.com/megamasha/FlashKard for anyone who wants to try it themselves. The window in question is generated from the 'resultswindow.ui' file.

Is this just me? Is this a bug? Just wondering if anyone can see any obvious reason why this doesn't work (or perhaps it just doesn't work on my Windows Vista system)

Was it helpful?

Solution

About QPushButton::default:

A button with this property set to true (i.e., the dialog's default button,) will automatically be pressed when the user presses enter, with one exception: if an autoDefault button currently has focus, the autoDefault button is pressed.

And more importantly:

Command buttons in dialogs are by default auto-default buttons, i.e. they become the default push button automatically when they receive the keyboard input focus.

Unless you explicitly set editButton's autoDefault to false, it is true. There might be some Windows specifics involved (without further hints, Windows focuses the control with the lowest ID, which is probably the case for editButton, since it's created first). Try either setting autoDefault to false, or explicitly call continueButton.setFocus()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top