如何使用PySide创建关键错误消息?

2024-06-28 15:45:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我好像碰到了砖墙。不管我做什么,创建一个关键错误消息框似乎都不起作用。以下是我迄今为止所做的尝试:

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

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

this tutorial(我知道,但到目前为止,它是有用的)。但是,执行此操作会出现以下错误:

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

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

Supported signatures:

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)

我也尝试了以下方法:

^{pr2}$

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


Tags: 消息错误unicode关键flagsignorepysideabort
2条回答

下面是一个简单的例子

import sys
from PySide import QtGui
app = QtGui.QApplication(sys.argv)
a=QtGui.QMessageBox.critical(None,'Error!',"Error Message!", QtGui.QMessageBox.Abort)

Here's an example from 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_())        

回答您的问题you can check the documentation:

^{pr2}$

在本例中,parent=self,title=自我.tr("QMessageBox.showCritical()),文本=对话框.MESSAGE,按钮=QtGui.QMessageBox.Abort| QtGui.QMessageBox.StandardButton.重试|QtGui.QMessageBox.StandardButton。忽略

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

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

相关问题 更多 >