QTextEdit末尾空格背景色不显示问题排查
QTextEdit插入带背景色字符串时末尾空格背景色不显示的问题
使用QTextEdit插入带背景色的字符串时,发现末尾空格无法显示背景色。我已编写了最小可复现示例(MCVE),不过重写代码后问题消失。
编辑补充:当窗口最大化时,空格的背景色会正常显示,我会继续排查原因。
最小可复现示例
from PySide2 import QtWidgets, QtGui, QtCore class Terminal(QtWidgets.QTextEdit): def __init__(self, handler, width=80, height=30): super().__init__() self.setStyleSheet("Terminal {background-color: black;" "color: white;" "font: 10pt Consolas}") self.setTextInteractionFlags(QtCore.Qt.NoTextInteraction) self.setPlainText("\n".join([" " * width] * height)) self._width = width self._cursor = self.textCursor() self._handler = handler(self) next(self._handler) def say(self, row, col, text, **kwargs): format = QtGui.QTextCharFormat() for key, value in kwargs.items(): getattr(format, f"set{key}")(value) start = row * (self._width + 1) + col self._cursor.setPosition(start) self._cursor.setPosition(start + len(text), QtGui.QTextCursor.KeepAnchor) self._cursor.insertText(text, format) app = QtWidgets.QApplication([]) @Terminal def widget(win): win.say(0, 0, "hello ", Background=QtGui.QColor("red")) yield widget.show() app.exec_()
请问我可能哪里操作出错了?
内容的提问来源于stack exchange,提问作者Dante S.
相关产品推荐
相关产品推荐

