如何使用 PySide 创建严重错误消息? [英] How do I create a critical error message using PySide?

查看:99
本文介绍了如何使用 PySide 创建严重错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我好像撞到了一堵砖墙.无论我做什么,创建一个严重错误消息框似乎都不起作用.这是我迄今为止尝试过的:

I seem to be hitting a brick wall. No matter what I do, creating a critical error Message Box just doesn't seem to be working. Here's what I've tried thus far:

flags = QtGui.QMessageBox.StandardButton.Abort
flags |= QtGui.QMessageBox.StandardButton.Ignore

result = QtGui.QMessageBox.critical(
    self,
    'CRITICAL ERROR',
    'Error Message',
    flags
    )

取自 本教程(老我知道,但到目前为止它一直有帮助).但是,这样做会出现以下错误:

As taken from this tutorial (old I know, but it's been helpful thus far). Doing this however, brings up the following error:

'PySide.QtGui.QMessageBox.critical' 调用了错误的参数类型:

'PySide.QtGui.QMessageBox.critical' called with wrong argument types:

PySide.QtGui.QMessageBox.critical(CreateMessage, str,标准按钮)

PySide.QtGui.QMessageBox.critical(CreateMessage, str, StandardButtons)

支持的签名:

PySide.QtGui.QMessageBox.critical(PySide.QtGui.QWidget, unicode,unicode,PySide.QtGui.QMessageBox.StandardButtons = QMessageBox.Ok,PySide.QtGui.QMessageBox.StandardButton = NoButton)

PySide.QtGui.QMessageBox.critical(PySide.QtGui.QWidget, unicode, unicode, PySide.QtGui.QMessageBox.StandardButtons = QMessageBox.Ok, PySide.QtGui.QMessageBox.StandardButton = NoButton)

PySide.QtGui.QMessageBox.critical(PySide.QtGui.QWidget, unicode,unicode,PySide.QtGui.QMessageBox.StandardButton,PySide.QtGui.QMessageBox.StandardButton)

PySide.QtGui.QMessageBox.critical(PySide.QtGui.QWidget, unicode, unicode, PySide.QtGui.QMessageBox.StandardButton, PySide.QtGui.QMessageBox.StandardButton)

我还尝试了以下方法:

result = QtGui.QMessageBox.critical(
    self,
    'CRITICAL ERROR',
    'Error Message',
    QtGui.QMessageBox.StandardButton.Abort
    )

# Or this....

result = QtGui.QMessageBox.critical(
    self,
    'CRITICAL ERROR', 
    'Error Message',
    QtGui.QMessageBox.Abort
    )

这些似乎都不能正常工作.如何创建严重错误消息框?

None of these seem to work properly. How do I create a critical error message box?

推荐答案

这是 Qt.Gitorious 的一个例子.

from PySide import QtGui, QtCore
import sys

class Dialog(QtGui.QDialog):
    MESSAGE = QtCore.QT_TR_NOOP("<p>Message boxes have a caption, a text, and up to "
                                "three buttons, each with standard or custom texts.</p>"
                                "<p>Click a button or press Esc.</p>")

    def __init__(self, parent=None):
        QtGui.QDialog.__init__(self, parent)
        self.criticalLabel = QtGui.QLabel()
        self.criticalLabel.setFrameStyle(QtGui.QFrame.Sunken | QtGui.QFrame.Panel)
        self.criticalButton = QtGui.QPushButton(self.tr("QMessageBox.critica&l()"))

        layout = QtGui.QGridLayout()
        layout.addWidget(self.criticalButton, 10, 0)
        layout.addWidget(self.criticalLabel, 10, 1)
        self.setLayout(layout)

        self.connect(self.criticalButton, QtCore.SIGNAL("clicked()"), self.criticalMessage)


    def criticalMessage(self):    
        reply = QtGui.QMessageBox.critical(self, self.tr("QMessageBox.showCritical()"),
                                               Dialog.MESSAGE, QtGui.QMessageBox.Abort|
                                               QtGui.QMessageBox.StandardButton.Retry|
                                               QtGui.QMessageBox.StandardButton.Ignore)
        if reply == QtGui.QMessageBox.Abort:
            self.criticalLabel.setText(self.tr("Abort"))
        elif reply == QtGui.QMessageBox.Retry:
            self.criticalLabel.setText(self.tr("Retry"))
        else:
            self.criticalLabel.setText(self.tr("Ignore"))

if __name__ == '__main__':  
    app = QtGui.QApplication(sys.argv)
    dialog = Dialog()
    sys.exit(dialog.exec_())        

回答你的问题 您可以查看文档:

static PySide.QtGui.QMessageBox.critical(parent, title, text[, buttons=QMessageBox.Ok[, defaultButton=NoButton]])

在示例中,parent = self, title = self.tr("QMessageBox.showCritical()"), text = Dialog.MESSAGE, buttons = QtGui.QMessageBox.Abort |QtGui.QMessageBox.StandardButton.Retry |QtGui.QMessageBox.StandardButton.Ignore

In the example, parent = self, title = self.tr("QMessageBox.showCritical()"), text = Dialog.MESSAGE, buttons = QtGui.QMessageBox.Abort | QtGui.QMessageBox.StandardButton.Retry | QtGui.QMessageBox.StandardButton.Ignore

tr 只是一些用于设置翻译的 Qt 函数,基本上它是一个字符串.我真的不能告诉你你做错了什么,看着错误信息,它似乎解析了错误的东西.可能是因为您为标志分配值的方式.

The tr is just some Qt function to set up translations, basically its a string. I can't really tell you what you did wrong, looking at the error message, it seems to have parsed things wrong. Possibly because of the way you assigned values to flags.

该示例还展示了如何处理关键对话框的结果,这似乎很有用.

The example also shows how to deal with the result of the critical dialog, which seems useful.

这篇关于如何使用 PySide 创建严重错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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