Как я могу обернуть setPlaceholderText в поле QPlainTextEdit? - PullRequest
1 голос
/ 13 июля 2020

У меня довольно длинный текст-заполнитель в поле QPlainTextEdit, но он не переносится. Хотя я установил атрибут setWordWrapMode на WordWrap. Есть ли способ добиться этого?

Вот скриншот из того, что я получил в Maya (2018):

enter image description here

The text should read Comment on what you have done here, i.e.: what changes were made or new clothing... but get cut off after "were". You kind of see the tip of the letters but thats it.

The following code works doesn't work in 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__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    window = TestDialog()
    window.show()
    app.exec_()

введите описание изображения здесь

1 Ответ

0 голосов
/ 14 июля 2020

Код работает в Maya 2020, но не в 2019 или 2018. Я предполагаю, что есть ошибка в Qt 5.6 (2018/2019) или в пакете Maya PySide2, исправленная в Qt 5.12 (2020).

К сожалению, это означает, что для более ранних версий, вероятно, нет простого исправления.

...