Dinosaur
Dinosaur

Reputation: 55

Is there a way to change QTreeView Header color in pyqt5?

I want to be able to change the column header but anything that I try it doesn't work. Below is example of what I want to change. I want to change the white of the header.

[Example]

1

Below is the style sheet that I have currently

self.treeView.setStyleSheet("background-color: rgb(0, 153, 255);\n"
                                    #"color: rgb(0, 153, 255);\n"
                                    "alternate-background-color: rgb(0, 153, 255);\n"
                                    "border-style: solid;\n"
                                    "border-color: rgb(0, 153, 255);\n"
                                    "border-width: 2px;\n"
                                    "border-radius: 10px;")

Let me know if you need more code!

Upvotes: 1

Views: 1590

Answers (1)

Passerby
Passerby

Reputation: 958

Here is a small complete application that shows how to set a header style for a QTreeView:

import sys
from PyQt5 import QtWidgets

class Widget(QtWidgets.QTreeView):
    def __init__(self):
        super().__init__()
        self.test_model = QtWidgets.QFileSystemModel(self)
        self.setModel(self.test_model)

app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet("QHeaderView::section { background-color: red }")
w = Widget()
w.show()
sys.exit(app.exec_())

For further information on styling the header see the docs.

Upvotes: 2

Related Questions