python - QtGui.QMessageBox.information 和自定义

标签 python qt pyqt qmessagebox

根据您的文档,QtGui.QMessageBox.information() 函数可用于创建带有多个按钮的对话框,使用以下常量:

QMessageBox.Ok  An “OK” button defined with the AcceptRole .
QMessageBox.Open    A “Open” button defined with the AcceptRole .
QMessageBox.Save    A “Save” button defined with the AcceptRole .
QMessageBox.Cancel  A “Cancel” button defined with the RejectRole .
QMessageBox.Close   A “Close” button defined with the RejectRole .
QMessageBox.Discard     A “Discard” or “Don’t Save” button, depending on the platform, defined with the DestructiveRole .
QMessageBox.Apply   An “Apply” button defined with the ApplyRole .
QMessageBox.Reset   A “Reset” button defined with the ResetRole .
QMessageBox.RestoreDefaults     A “Restore Defaults” button defined with the ResetRole .
QMessageBox.Help    A “Help” button defined with the HelpRole .
QMessageBox.SaveAll     A “Save All” button defined with the AcceptRole .
QMessageBox.Yes     A “Yes” button defined with the YesRole .
QMessageBox.YesToAll    A “Yes to All” button defined with the YesRole .
QMessageBox.No  A “No” button defined with the NoRole .
QMessageBox.NoToAll     A “No to All” button defined with the NoRole .
QMessageBox.Abort   An “Abort” button defined with the RejectRole .
QMessageBox.Retry   A “Retry” button defined with the AcceptRole .
QMessageBox.Ignore  An “Ignore” button defined with the AcceptRole .
QMessageBox.NoButton    An invalid button.

它支持许多功能。

我一直在使用 QMessageBox 的文档类。

我的问题是,如何更改消息框中按钮的文本?

最佳答案

QMessageBox::setButtonText正是您所需要的。

编辑:

感谢Bakuriu感谢您指出这一点。

上面提到的 setButtonText 方法在与针对 Qt4.3 或更早版本编译的 PyQt/PySide 库一起使用时可以工作。 Source .

对于更高版本,更改按钮的文本将涉及:

button = messageBox.button(which)

button.setText(text)

关于python - QtGui.QMessageBox.information 和自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679504/

相关文章:

python - 神秘的换行符被添加到 QPlainTextEdit 的末尾

python - 如何使用 Apache Spark Dataframes 执行 Switch 语句 (Python)

qt - QFrame 的样式表影响 QLabel

c++ - 编译时生成信息文件

c++ - Qt问题将参数传递给插槽

python - 如何在 Linux 下使用 python 创建一个具有炫酷动画/效果的 GUI 应用程序(如 Cooliris 中的 3D 墙、compiz 效果等...)

Python PyQt5 打印多色到纯文本编辑

python - 在指定范围内查找系列中两个数字的索引的算法

python - PyCharm 和 Python 控制台

python - 文字游戏问题