Форум сайта python.su
Можно ли как-то установить межстрочный интервал в QTextEdit?
Офлайн
Офлайн
RodegastВыдает ошибку, ну или скорее всего, я что-то не так делаю.
https://coderoad.ru/10250533/%D0%A3%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%B8%D1%82%D1%8C-%D0%BC%D0%B5%D0%B6%D0%B4%D1%83%D1%81%D1%82%D1%80%D0%BE%D1%87%D0%BD%D1%8B%D0%B9-%D0%B8%D0%BD%D1%82%D0%B5%D1%80%D0%B2%D0%B0%D0%BB-%D0%B2-QTextEdit
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, QMetaObject, QObject, QPoint, QRect, QSize, QTime, QUrl, Qt) from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont, QFontDatabase, QGradient, QIcon, QImage, QKeySequence, QLinearGradient, QPainter, QPalette, QPixmap, QRadialGradient, QTransform) from PySide6.QtWidgets import (QApplication, QMainWindow, QSizePolicy, QTextEdit, QVBoxLayout, QWidget) class Ui_MainWindow(object): def setupUi(self, MainWindow): if not MainWindow.objectName(): MainWindow.setObjectName(u"MainWindow") MainWindow.resize(363, 208) self.centralwidget = QWidget(MainWindow) self.centralwidget.setObjectName(u"centralwidget") self.verticalLayout = QVBoxLayout(self.centralwidget) self.verticalLayout.setObjectName(u"verticalLayout") self.textEdit = QTextEdit(self.centralwidget) self.textEdit.setObjectName(u"textEdit") font = QFont() font.setPointSize(14) self.textEdit.setFont(font) self.verticalLayout.addWidget(self.textEdit) MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) # setupUi def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None)) # retranslateUi
from ui_untitled import * from PySide6.QtGui import QTextBlockFormat from sys import argv, exit class Test(QMainWindow, Ui_MainWindow): def __init__(self): super().__init__() self.setupUi(self) self.textEdit.setText('Sample text Sample text Sample text Sample text Sample text Sample text Sample text ' 'Sample text Sample text Sample text Sample text Sample text Sample text Sample text') bf = self.textEdit.textCursor().blockFormat() bf.setLineHeight(50, QTextBlockFormat.LineDistanceHeight) bf.setLineHeight(lineSpacing, QTextBlockFormat.LineDistanceHeight) self.textEdit.textCursor().setBlockFormat(bf) if __name__ == "__main__": app = QApplication(argv) window = Test() window.show() exit(app.exec())
Офлайн
Убери строку
bf.setLineHeight(lineSpacing, QTextBlockFormat.LineDistanceHeight)
Офлайн
RodegastВсе равно не работает.
и будет норм.
Офлайн