PyQt QTableWidget horizontalheaderlabel stylesheet

2019-09-16 02:16发布

问题:

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?

回答1:

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)