1 Attachment(s)
QTableWidget Background Color
This code produces a table of toolbuttons (see attachment). How do I set the background color of the table to something other than its default white background?
#include <QtGui>
#include <QApplication>
int main( int argc, char *argv[] )
{
QApplication app( argc, argv );
QDialog *d = new QDialog;
d->setWindowTitle( "Table Test" );
QTableWidget *table = new QTableWidget( 2, 3 );
QStringList headers = QStringList() << "A" << "B" << "C";
table->setHorizontalHeaderLabels( headers );
table->setGridStyle( Qt::NoPen );
table->setCellWidget( 0, 0, new QToolButton );
table->setCellWidget( 0, 1, new QToolButton );
table->setCellWidget( 0, 2, new QToolButton );
table->setCellWidget( 1, 0, new QToolButton );
table->setCellWidget( 1, 1, new QToolButton );
table->setCellWidget( 1, 2, new QToolButton );
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget( table );
d->setLayout( layout );
d->show();
return app.exec();
}
Re: QTableWidget Background Color
Style sheets might help you. Try calling setStyleSheet("background: rgb(200, 255, 200)") on your table widget.
Re: QTableWidget Background Color
one way is to subclass QTableWidget and repaint the background in the derived classes paint event......