更改QPlainTextEdit中某些行的背景颜色
Change the background color of some lines in QPlainTextEdit
这不起作用:
def lineError(self):
block= self.firstVisibleBlock()
while block.isValid():
if block.blockNumber() in self.lineError:
block.blockFormat().setBackground(QBrush(self.errorColor))
block.charFormat().setBackground(QBrush(self.errorColor))
block= block.next()
你有什么想法吗?
正确的方法:
fmt= QTextBlockFormat()
fmt.setBackground(self.errorColor)
while block.isValid():
if block.blockNumber() in self.lineError:
QTextCursor(block).setBlockFormat(fmt)
block= block.next()
这不起作用:
def lineError(self):
block= self.firstVisibleBlock()
while block.isValid():
if block.blockNumber() in self.lineError:
block.blockFormat().setBackground(QBrush(self.errorColor))
block.charFormat().setBackground(QBrush(self.errorColor))
block= block.next()
你有什么想法吗?
正确的方法:
fmt= QTextBlockFormat()
fmt.setBackground(self.errorColor)
while block.isValid():
if block.blockNumber() in self.lineError:
QTextCursor(block).setBlockFormat(fmt)
block= block.next()