pythonpyqtpyqt4stylesheet

PyQt QTableWidget horizontalheaderlabel stylesheet


I used this to set the style for my QTableWidget. Everything in the table is affected except the horizontalheaderlabels and the row numbers.

Table.setStyleSheet("Background-color:rgb(100,100,100);border-radius:15px;")

So I tried this

Table.horizontalHeader().setStyleSheet("Background-color:rgb(190,1,1);border-radius:14px;"

But this doesn't seems to have any affect.

How do i set the style sheet for horizontalheaderlabel and the row numbers?


Solution

  • You should check Qt Sylesheet Reference

    You have to do something like

    stylesheet = "::section{Background-color:rgb(190,1,1);border-radius:14px;}"
    Table.horizontalHeader().setStyleSheet(stylesheet)
    

    That is if you want different horizontal and vertical headers. Otherwise, this should do the job

    stylesheet = "QHeaderView::section{Background-color:rgb(190,1,1);
                                       border-radius:14px;}"
    Table.setStyleSheet(stylesheet)