Search code examples
pythonpyqtpyqt4qlistwidgetqlistwidgetitem

How to customize QListWidget background color (and not QListWidgetItem)


I wonder if there is a way to customize QListWidget background color.

I have tried:

listWidget=QtGui.QListWidget()
listWidget.setAutoFillBackground(True)
p = listWidget.palette()
p.setColor(listWidget.backgroundRole(), QtGui.QColor("#424242"))
listWidget.setPalette(p)

While there were no errors it still doesn't work.


Solution

  • You can set a stylesheet that changes the background:

    self.setStyleSheet( """QListWidget{
                        background: yellow;
                    }
                    """
    )
    

    Example output:

    SS