PDA

View Full Version : How to change background color of QTableWidget horizontalHeaderItem?



cutie.monkey
16th July 2010, 05:25
Hi! I'm trying to change the background color of my QTableWidget horizontal header item but it's not working.



QTableWidgetItem *tblCol1 = new QTableWidgetItem("Column 1");
tblCol1->setBackground(Qt::red);
tableWidget->setHorizontalHeaderItem(0, tblCol1);


Is there other way to do this?

thanks..

norobro
16th July 2010, 21:53
Works fine here.
#include <QtGui/QApplication>
#include <QTableWidget>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QTableWidget tableWidget(2,2);
QTableWidgetItem *tblCol1 = new QTableWidgetItem("Column 1");
tblCol1->setBackground(Qt::red);
tableWidget.setHorizontalHeaderItem(0, tblCol1);
tableWidget.show();

return a.exec();
}
4911

cutie.monkey
17th July 2010, 03:23
I've tried to compile the same source code in WINDOWS and LINUX(Ubuntu) using Qt 4.6.1 but both are not working..:confused:

norobro
17th July 2010, 04:39
That screen shot is from a Debian Sid box running Qt 4.7 Beta 1. I just tried it on Windows XP running Qt 4.6.2 and the background wasn't changed. :confused: indeed!

saa7_go
17th July 2010, 05:47
You can read about Qt Style Sheets (http://doc.trolltech.com/4.6/stylesheet.html), and Customizing QHeaderView (http://doc.trolltech.com/4.6/stylesheet-examples.html#customizing-qheaderview).