Order of push buttons on different platforms (QDia

2019-08-14 04:17发布

The QDialogButtonBox widget automatically reorders it's buttons to meet the expectations of users on different platforms. I'd like to follow this behavior, but with my own button labels (e.g. 'Import' instead of 'OK'). How can I achieve this? Is it possible to use QMessageBox, or do I need to write my own implementation? I'm writing my application with PyQt4, and Qt Designer.

See screenshot below of QDialogButtonBox on OS X in Aqua and Cleanlooks styles.

QDialogButtonBox

标签: python qt pyqt4
1条回答
Root(大扎)
2楼-- · 2019-08-14 04:20

QDialogButtonBox can do this for you, but you will need to create a dialog to put one in first (a trivial amount of work).

...
auto buttons = new QDialogButtonBox( this );
buttons->addButton( "Import", QDialogButtonBox::AcceptRole );
buttons->addButton( "Cancel", QDialogButtonBox::RejectRole );
...

The docs are here (it's C++, but I'm sure can follow it), the general idea is that ButtonRole is used by the current style layout to rearrange the buttons.

查看更多
登录 后发表回答