roleroz
19th October 2006, 18:18
I'm trying to have a list of special kind of widgets, with different background colors for each one and the alternatingRowColor flag doesn't seem to work
I'm using a QTableWidget and setting the widgets for each cell. Using the 4.1.4 version of QT
have some code, that should do it, but doesn't work
#include <QtGui/QApplication>
#include <QtGui/QLabel>
#include <QtGui/QTableWidget>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTableWidget table(5,1);
table.setAlternatingRowColors(true);
table.show();
QPalette palette;
QWidget *widget;
widget = new QLabel("bla", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(0, 0, widget);
widget = new QLabel("ble", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(1, 0, widget);
widget = new QLabel("bli", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(2, 0, widget);
widget = new QLabel("blo", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(3, 0, widget);
widget = new QLabel("blu", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(4, 0, widget);
return app.exec();
}
Any ideas??
I'm using a QTableWidget and setting the widgets for each cell. Using the 4.1.4 version of QT
have some code, that should do it, but doesn't work
#include <QtGui/QApplication>
#include <QtGui/QLabel>
#include <QtGui/QTableWidget>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTableWidget table(5,1);
table.setAlternatingRowColors(true);
table.show();
QPalette palette;
QWidget *widget;
widget = new QLabel("bla", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(0, 0, widget);
widget = new QLabel("ble", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(1, 0, widget);
widget = new QLabel("bli", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(2, 0, widget);
widget = new QLabel("blo", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(3, 0, widget);
widget = new QLabel("blu", &table);
palette = widget->palette();
palette.setColor(QPalette::Base, Qt::green);
palette.setColor(QPalette::AlternateBase, Qt::red);
widget->setPalette(palette);
table.setCellWidget(4, 0, widget);
return app.exec();
}
Any ideas??