这不起作用:
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()
你有什么想法吗?
答案 0 :(得分:1)
正确的方式:
fmt= QTextBlockFormat()
fmt.setBackground(self.errorColor)
while block.isValid():
if block.blockNumber() in self.lineError:
QTextCursor(block).setBlockFormat(fmt)
block= block.next()