
Originally Posted by
Erik_Klein
QHeaderView::section
{
spacing: 10px;
background-color:lightblue;
color: white;
border: 1px solid red;
margin: 1px;
text-align: right;
font-family: arial;
font-size:12px;
}
but this applies to all the headers.
If you want that to applly to a specific header, you can do it manually by code.
QString styleSheet
= "::section {" // "QHeaderView::section {" "spacing: 10px;"
"background-color: lightblue;"
"color: white;"
"border: 1px solid red;"
"margin: 1px;"
"text-align: right;"
"font-family: arial;"
"font-size: 12px; }";
tableWidget->horizontalHeader()->setStyleSheet(styleSheet); // tableWidget->verticalHeader()->setStyleSheet(styleSheet);
QString styleSheet = "::section {" // "QHeaderView::section {"
"spacing: 10px;"
"background-color: lightblue;"
"color: white;"
"border: 1px solid red;"
"margin: 1px;"
"text-align: right;"
"font-family: arial;"
"font-size: 12px; }";
tableWidget->horizontalHeader()->setStyleSheet(styleSheet); // tableWidget->verticalHeader()->setStyleSheet(styleSheet);
To copy to clipboard, switch view to plain text mode

Originally Posted by
Erik_Klein
then, if i want multiple background colors, there is only one way to do it which is...
Maybe, you can use QTableWidgetItem and QTableWidget::setHorizontalHeaderItem(int, QTableWidgetItem*).
col1->setForeground(Qt::white);
col1
->setBackground
(QColor("lightblue"));
col1
->setFont
(QFont("arial",
12));
tableWidget->setHorizontalHeaderItem(0, col1); // tableWidget->setVerticalHeaderItem(0, col1);
QTableWidgetItem *col1 = new QTableWidgetItem("Column 1");
col1->setForeground(Qt::white);
col1->setBackground(QColor("lightblue"));
col1->setFont(QFont("arial", 12));
tableWidget->setHorizontalHeaderItem(0, col1); // tableWidget->setVerticalHeaderItem(0, col1);
To copy to clipboard, switch view to plain text mode
But, the background color doesn't work for me.
Bookmarks