gpt4 book ai didi

python - QMessageBox 防止在 DetailsText 中换行

转载 作者:行者123 更新时间:2023-12-04 09:09:35 25 4
gpt4 key购买 nike

我正在尝试构建一个消息对话框,显示对我的 UI 的影响的详细信息。这个列表足够长,需要一个滚动条,但文本足够长,我希望线条不被破坏。似乎改变 QMessage 对话框的大小很难,因为它会根据其内容对其进行计算。有没有办法“鼓励那个详细的框来防止换行?
或者允许调整 QMessageBox 的大小

impacts = []
# Create Impacts
for i in range(0, 100):
impacts.append(" This is a text can be a little long but not too long impact {}".format(i))

# CreateDialog
diffBox = QMessageBox()
diffBox.setWindowTitle("Test")
diffBox.setInformativeText(
"Impacts have been found, and this message is long but not too long as well but independent of the list")
diffBox.setDetailedText("changes:\n\n" + "\n".join(impacts))

# Add Buttons
diffBox.addButton("Apply", QMessageBox.AcceptRole)
diffBox.setStandardButtons(QMessageBox.Cancel)
diffBox.setSizeGripEnabled(True)
result = diffBox.exec_()
enter image description here
enter image description here

最佳答案

您必须获得 QTextEdit 并禁用换行:

from Qt.QtCore import Qt
from Qt.QtWidgets import QApplication, QMessageBox, QTextEdit


if __name__ == "__main__":
import sys

app = QApplication(sys.argv)
impacts = []
# Create Impacts
for i in range(0, 100):
impacts.append(
" This is a text can be a little long but not too long impact {}".format(i)
)

# CreateDialog
diffBox = QMessageBox()
diffBox.setWindowTitle("Test")
diffBox.setInformativeText(
"Impacts have been found, and this message is long but not too long as well but independent of the list"
)
diffBox.setDetailedText("changes:\n\n" + "\n".join(impacts))

# Add Buttons
diffBox.addButton("Apply", QMessageBox.AcceptRole)
diffBox.setStandardButtons(QMessageBox.Cancel)
diffBox.setSizeGripEnabled(True)

te = diffBox.findChild(QTextEdit)
if te is not None:
te.setLineWrapMode(QTextEdit.NoWrap)
te.parent().setFixedWidth(
te.document().idealWidth()
+ te.document().documentMargin()
+ te.verticalScrollBar().width()
)

result = diffBox.exec_()
enter image description here

关于python - QMessageBox 防止在 DetailsText 中换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63381495/

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