6

I would like to change the colors of a QTableWidget. I am almost getting the result I like, but two areas in the vertical header remain white:

enter image description here

Before writing this post I actually managed to color also the upper left corner, but not the other area. Here is the stylesheet I am using:

QTableCornerButton::section {
    background-color: #8b8d8e;
}

QHeaderView::section {
    color: white;
    background-color: #747678;
    gridline-color: #747678;
}
scopchanov
  • 7,966
  • 10
  • 40
  • 68
JoeCool
  • 129
  • 7

2 Answers2

3

Finally found the answer myself:

/*The top-left area is actually a button:*/
QTableCornerButton::section {
    background-color: #8b8d8e;
}
/*The lower part of the vertical header:*/
QHeaderView {
    background-color: #8b8d8e;
}

The original css I posted (QHeaderView::section) referred only to the header entries, not the header itself.

JoeCool
  • 129
  • 7
0

QTableCornerButton is a private class of QTableWidget, you can enable and disable the button using the function QTableView::setCornerButtonEnabled, however, if you disable the button, that corner abstract button has a white background.

It is different from QAbstractScrollArea::cornerWidget, you can set another widget with setCornerWidget, but it won't override.

Even if the class is private, it can be acessed with the following code:

QAbstractButton* qCorner = this->findChild<QAbstractButton *>();

Where this is a wrapper class for QTableWidget or use yourTableObj instead of this.

And then you can style:

qCorner->setStyleSheet("QTableCornerButton::section {"
                       "border: 0px;"
                       "background-color: " + QColor(Qt::black).name() +
                       ";}");

It is useful when you don't want to use stylesheet on the entire Table, be cause either you are using some Item delegates or using QPalette.

danieltakeshi
  • 887
  • 9
  • 37