不同平台上的按钮顺序 (QDialogBu​​ttonBox) [英] Order of push buttons on different platforms (QDialogButtonBox)

查看:49
本文介绍了不同平台上的按钮顺序 (QDialogBu​​ttonBox)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QDialogBu​​ttonBox 小部件会自动对其按钮重新排序,以满足不同平台用户的期望.我想遵循这种行为,但使用我自己的按钮标签(例如导入"而不是确定").我怎样才能做到这一点?是否可以使用 QMessageBox,或者我是否需要编写自己的实现?我正在使用 PyQt4 和 Qt Designer 编写我的应用程序.

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.

请参阅以下 OS X 上 Aqua 和 Cleanlooks 样式的 QDialogBu​​ttonBox 屏幕截图.

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

推荐答案

QDialogBu​​ttonBox 可以为您做到这一点,但您需要创建一个对话框来将其放在第一位(工作量微不足道)).

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

文档在这里(它是 C++,但我是肯定可以跟上),大体思路是ButtonRole被当前样式布局用来重新排列按钮.

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.

这篇关于不同平台上的按钮顺序 (QDialogBu​​ttonBox)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆