1

当我在 PySide 的 QMessageBox 上使用 setDetailedText 时,“显示详细信息...”按钮将自身置于“确定”和“取消”按钮之间。有没有办法控制按钮的位置?我喜欢它在文档中的显示方式,但我希望使用不同的按钮来查看它,例如确定和取消。我希望“显示详细信息”按钮位于左侧,而“确定”和“取消”位于右侧。

我完全明白我可以使用基于 QDialog 的完全自定义 GUI 来实现这一点,但我对 MessageBox 是否可以做我想做的事情很感兴趣。

这是我的例子:

import sys
from PySide import QtCore
from PySide import QtGui


class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None, args=()):
        super(MyForm, self).__init__(parent)

        self.centralLayout = QtGui.QVBoxLayout()
        self.centralWidget = QtGui.QWidget()
        self.centralWidget.setLayout(self.centralLayout)
        self.setCentralWidget(self.centralWidget)

        self.button = QtGui.QPushButton()
        self.button.setText("Push Me")
        self.button.clicked.connect(self.show_message)
        self.centralLayout.addWidget(self.button)

    def show_message(self):

        msg = QtGui.QMessageBox()
        msg.setWindowTitle("Here's a Title")
        msg.setText("Here's some text")
        msg.setInformativeText("Here's some more text")
        msg.setDetailedText("Here's a whole bunch more detailed text than you might possibly want to know if you're interested.")
        msg.setStandardButtons(QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok)
        msg.setDefaultButton(QtGui.QMessageBox.Ok)
        ret = msg.exec_()

        app.exit()

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    MyApp = MyForm()
    MyApp.show()
    sys.exit(app.exec_())
4

0 回答 0