[Development] QDialog vs QPushButton and it's autoDefault default
Bernhard Lindner
private at bernhard-lindner.de
Mon Feb 11 22:47:41 CET 2019
Hi!
I just experienced same strange behavior of QPushButton. I want to kindly ask for some
explanations.
I wrote a QDialog derived dialog. That dialog has a standard QDialogButtonBox with
"Accept" and "Close" buttons. It also has various other widgets, especially a table view
for item selection and a more complex generic/reusable filter panel (QWidget derived) that
can be attached to any table view for complex user side filtering. That panel contains
various widgets, including two buttons.
I now have tripped painfully over a strange behavior that I could track back to the fact
that one of those two buttons was automagically set as the dialog's default button. Now,
whenever a user presses <Enter> to confirm QLineEdit filter input, also the mentioned
clear button is activated - causing a fabulous mess.
After some research I could explain that unexpected behavior:
autoDefault : bool
This property holds whether the push button is an auto default button.
...
This property's default is true for buttons that have a QDialog parent
This also means there is a workaround: I need to call "setAutoDefault(false)" on each
button that has the slightest chance to be ever used in a dialog. Everywhere. That is
doable but seems very counterintuitive to me.
So my questions are:
1. Is this actually how the autoDefault mechanism should work?
2. Why an opt-out instead of an opt-in?
3. Regarding opt-out: Why not restricting the autoDefault default of true to buttons with
QDialogButtonBox parents instead of QDialog parents?
4. Anyway, is it good style to change the default value (!) of a property dynamically like
this?
Thanks in advance!
--
Best Regards,
Bernhard Lindner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <http://lists.qt-project.org/pipermail/development/attachments/20190211/ec579664/attachment.sig>
More information about the Development
mailing list