Mauricio
Mauricio

Reputation: 742

Change the background color of some lines in QPlainTextEdit

This does not work:

    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()

Have you any idea?

Upvotes: 1

Views: 1710

Answers (1)

Mauricio
Mauricio

Reputation: 742

The right way:

        fmt= QTextBlockFormat()
        fmt.setBackground(self.errorColor)
        while block.isValid():
            if block.blockNumber() in self.lineError:
                QTextCursor(block).setBlockFormat(fmt)
            block= block.next()

Upvotes: 1

Related Questions