QTableWidget horizontal QHeader background color don't change
-
When creating a new QTableWidget and changing the QPalette to the following QPalette:
The result is that the horizontal background of the QHeader don't change the color:
ps.: To change the color of each Item of the header, it is possible to set each individual QTableWidgetItem. However, the background on the right of the horizontal header remains white.
I don't want to use stylesheet, however, with the following stylesheet code:
background-color:black
The entire TableWidget turns black:
How can QPalette paint the horizontal header background as it is done with the vertical header? With a pink color on the example.
ps.: It was not possible to setPalette on the horizontalHeader()
-
@dwatanabe
Try this:QPalette pal = tableWidget->palette(); pal.setColor(QPalette::Window, Qt::black); tableWidget->setPalette(pal);
[EDIT] it works with horizontal header as well:
auto hd=tableWidget->horizontalHeader(); pal = hd->palette(); pal.setColor(QPalette::Window, Qt::magenta); hd->setPalette(pal);
-
I tried it before, but isn't working, I am using Qt 6.4.2
QPalette qPal = ui->tableWidget->palette(); qPal.setColor(QPalette::Base, Qt::black); // Header Background qPal.setColor(QPalette::Button, Qt::black); // Outline qPal.setColor(QPalette::Window, Qt::black); // Header Text qPal.setColor(QPalette::ButtonText, Qt::black); // Body Text qPal.setColor(QPalette::Text, Qt::black); // Highlight qPal.setColor(QPalette::Highlight, Qt::black); // Highlight Text qPal.setColor(QPalette::HighlightedText, Qt::black); //3D Bevel qPal.setColor(QPalette::Dark, Qt::black); qPal.setColor(QPalette::Light, Qt::black); ui->tableWidget->horizontalHeader()->setPalette(qPal);
Result for
ui->tableWidget->horizontalHeader()->setPalette(qPal);
:Result for
ui->tableWidget->horizontalHeader()->setPalette(qPal);
-
@mpergand said in QTableWidget horizontal QHeader background color don't change:
For me with Qt 5.12, with your code the header is all black (text, background, etc)
Also on windows?
See QPalette documentation: "Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows Vista and the macOS styles." -
@Christian-Ehrlicher Yes, you are right, it only breaks on Windows.
I tested on a Remote Linux Device and it works just for the horizontal header:
Or on the entire QTableWidget:
Maybe I have to reimplement the QPainter on Windows?