简体   繁体   English

如何将 setPlaceholderText 包装在 QPlainTextEdit 字段中?

[英]How can I wrap the setPlaceholderText in a QPlainTextEdit field?

I have a somewhat lengthy placeholder text in the QPlainTextEdit field but it won't wrap around.我在QPlainTextEdit字段中有一个有点长的占位符文本,但它不会环绕。 Even though I set the setWordWrapMode attr to WordWrap .即使我将setWordWrapMode attr 设置为WordWrap Is there any way to achieve that?有没有办法做到这一点?

Here is a screenshot from what I get in Maya (2018):这是我在 Maya (2018) 中获得的屏幕截图:

在此处输入图像描述

The text should read Comment on what you have done here, ie: what changes were made or new clothing... but get cut off after "were".文本应为Comment on what you have done here, ie: what changes were made or new clothing...但在“是”之后被切断。 You kind of see the tip of the letters but thats it.你有点看到字母的尖端,但就是这样。

The following code works doesn't work in Maya:以下代码在 Maya 中不起作用:

import sys
from PySide2 import QtCore
from PySide2 import QtWidgets


class TestDialog(QtWidgets.QWidget):

    def __init__(self):
        super(TestDialog, self).__init__()

        self.setWindowTitle("testing")

        self.create_widgets()
        self.create_layout()

    def create_widgets(self):
        self.notes_ql = QtWidgets.QLabel()
        self.notes_ql.setText('Notes: ')
        self.notes_ql.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
        self.notes_pt = QtWidgets.QPlainTextEdit()
        self.notes_pt.setFixedHeight(100)
        self.notes_pt.setLineWrapMode(QtWidgets.QPlainTextEdit.WidgetWidth)
        self.notes_pt.verticalScrollBar().setValue(self.notes_pt.verticalScrollBar().minimum())
        self.notes_pt.setPlaceholderText('Comment on what you have done here, i.e.: what changes were made or new clothing...')


    def create_layout(self):
        notes_layout = QtWidgets.QHBoxLayout()
        notes_layout.addWidget(self.notes_ql)
        notes_layout.addWidget(self.notes_pt)

        main_layout = QtWidgets.QHBoxLayout(self)
        main_layout.setSpacing(1)
        main_layout.setContentsMargins(6, 6, 6, 6)
        main_layout.addLayout(notes_layout)


if __name__ == '__main__':
    try:
        test_dialog.close()  # pylint: disable=E0601
        test_dialog.deleteLater()
    except:
        pass

    test_dialog = TestDialog()
    test_dialog.show()
 

Replacing the if __name__ statement with the code snippet below so it runs as a standalone app work:用下面的代码片段替换if __name__语句,使其作为独立应用程序运行:

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = TestDialog()
    window.show()
    app.exec_()

在此处输入图像描述

The code works in Maya 2020, but not 2019 or 2018. My guess is that there is a bug in Qt 5.6 (2018/2019) or Maya's PySide2 package that was fixed in Qt 5.12 (2020).该代码在2020年,但不工作2019或2018年。我的猜测是,Ze8801102a40ad89ddfcfdcaebf008d25z 5.6(2018/2019)中有一个错误

Unfortunately, this means there is likely no easy fix for earlier versions.不幸的是,这意味着早期版本可能没有简单的修复方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM