gpt4 book ai didi

python - PyQt:带有 3 个选项的 QDialogBu​​ttonBox

转载 作者:行者123 更新时间:2023-12-03 09:03:11 24 4
gpt4 key购买 nike

我正在尝试通过三个按钮对话框为用户创建警报,询问他们是否要保存更改,或者完全取消操作。我可以管理"is"和“取消”,但“不保存”选项不起作用。这是我所拥有的:

import logging
import Qt
# from functools import wraps
from Qt import QtGui, QtCore, QtWidgets

dialog = QtWidgets.QDialog() #parent=parent)
dialog.setWindowTitle("Foo")
dialog.verticalLayout = QtWidgets.QVBoxLayout(dialog)

# Create the dialogs main message (Qlabel)
dialog.label = QtWidgets.QLabel(dialog)
dialog.label.setAlignment(QtCore.Qt.AlignCenter)
dialog.label.setTextInteractionFlags(dialog.label.textInteractionFlags() | QtCore.Qt.TextBrowserInteraction)
dialog.label.setTextFormat(QtCore.Qt.RichText)
dialog.label.setOpenExternalLinks(True)
dialog.label.setText("Magoo?")
dialog.verticalLayout.addWidget(dialog.label)

dialog.widget = QtWidgets.QWidget(dialog)
dialog.horizontalLayout = QtWidgets.QHBoxLayout(dialog.widget)
dialog.horizontalLayout.setContentsMargins(-1, -1, -1, 0)
dialog.horizontalLayout.setObjectName("horizontalLayout")
dialog.verticalLayout.addWidget(dialog.widget)

# Create the buttonbox with options
dialog.buttonBox = QtWidgets.QDialogButtonBox(dialog.widget)
dialog.buttonBox.setOrientation(QtCore.Qt.Horizontal)
dialog.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Discard | QtWidgets.QDialogButtonBox.Cancel | QtWidgets.QDialogButtonBox.Yes)
dialog.horizontalLayout.addWidget(dialog.buttonBox)

# Connect the buttonbox signals
dialog.buttonBox.accepted.connect(dialog.accept)
dialog.buttonBox.rejected.connect(dialog.reject)
QtCore.QMetaObject.connectSlotsByName(dialog)

# Resize the dialog box to scale to its contents
dialog.adjustSize()

# Launch the dialog
yes = dialog.exec_()
dont_notify_again = dialog.checkBox.isChecked()

我可能错过了与信号的连接应该是什么,但我不确定它们是什么。

最佳答案

在您的代码中尝试此解决方案。

result = QtGui.QMessageBox.question(self,
"Message-Box title",
"Message description",
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No | QtGui.QMessageBox.Save)
if result == QtGui.QMessageBox.Yes:
print "Yes "
elif result == QtGui.QMessageBox.No:
print "No "
elif result == QtGui.QMessageBox.Save:
print "Save "

关于python - PyQt:带有 3 个选项的 QDialogBu​​ttonBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48857367/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com