[PyQt] Re: TextEdit background color

Lee Harr missive at hotmail.com
Wed Dec 9 22:59:20 GMT 2009

> I use TextEdit widget, and i want that it's background color will
> black (for example)
> I tried to use TextEdit.setTextBackgroundColor but only background
> of text painted by black color.
> How can i color all TextEdit area by any color?

I have a QTextEdit subclass with black background, python syntax
highlighting and line numbers here:


But for just the background part:

from PyQt4 import QtGui

class TE(QtGui.QTextEdit):
    def __init__(self):
        pal = QtGui.QPalette()
        bgc = QtGui.QColor(0, 0, 0)
        pal.setColor(QtGui.QPalette.Base, bgc)
        textc = QtGui.QColor(255, 255, 255)
        pal.setColor(QtGui.QPalette.Text, textc)

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    widget = TE()

Windows Live: Make it easier for your friends to see what you’re up to on Facebook.

More information about the PyQt mailing list