如何将自定义按钮添加到 PyQt4 中的 QMessageBox [英] How to add custom button to a QMessageBox in PyQt4

查看:43
本文介绍了如何将自定义按钮添加到 PyQt4 中的 QMessageBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要 QMessageBox 中的自定义按钮的应用程序.我设法在 QT 设计器中创建了一个示例,如下所示.

I am coding a application which needs a custom buttons in QMessageBox. i managed to create an example in QT designer which is given below.

我想在 QMessageBox 中执行此操作.

i wanted to do this in a QMessageBox.

我使用的是 python 2.6.4 和 PyQt4.拜托,有人可以帮忙吗.

I am using python 2.6.4 and PyQt4. please, can any one help.

推荐答案

这是一个从头开始构建自定义消息框的示例.

Here is an example of building a custom message box from the ground up.

import sys
from PyQt4 import QtCore, QtGui


class Example(QtGui.QDialog):
    def __init__(self, parent=None):
        super(Example, self).__init__(parent)

        msgBox = QtGui.QMessageBox()
        msgBox.setText('What to do?')
        msgBox.addButton(QtGui.QPushButton('Accept'), QtGui.QMessageBox.YesRole)
        msgBox.addButton(QtGui.QPushButton('Reject'), QtGui.QMessageBox.NoRole)
        msgBox.addButton(QtGui.QPushButton('Cancel'), QtGui.QMessageBox.RejectRole)
        ret = msgBox.exec_()


if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    ex = Example()
    ex.show()
    sys.exit(app.exec_())

这篇关于如何将自定义按钮添加到 PyQt4 中的 QMessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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