Search code examples
pythonmacospyqthighlightqtstylesheets

PyQt Change Active Widget Highlight Colour


I have a PyQt window with a custom stylesheet. On MacOS the QLineEdit is highlighted in blue when it is active, which ruins the stylesheet I am using. Is there any way to either stop this from happening or change the highlight colour that is used?

Window


Solution

  • You can change it using the QPalette:

    le = QtWidgets.QLineEdit()
    pal = le.palette()
    pal.setColor(
        QtGui.QPalette.Active, QtGui.QPalette.Highlight, QtGui.QColor("black")
    )
    le.setPalette(pal)