I stripped my problem down to a simple testcase. I want to display the rows of a QTableWidget with alternating colors using a stylesheet.
When running the program with the -stylesheet widgettest.qss option, I only see the default colors for the alternating background, not the colors defined in the stylesheet.
I expected either the first or second entry to use yellow as background but that is not the case as you can see in the screenshot. Any Idea what I'm doing wrong?
Here's the code
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QTableWidget>
{
Q_OBJECT
public:
~MainWindow();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QTableWidget>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
QTableWidget *myTable;
~MainWindow();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
myTable->setColumnCount(1);
myTable->setRowCount(5);
myTable->show();
myTable->insertRow(0);
myTable->setItem(0,0,myTableWidget);
myTable->setItem(1,0,myTableWidget2);
myTable->resizeColumnsToContents();
myTable->setAlternatingRowColors(true);
}
MainWindow::~MainWindow()
{
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
myTable=new QTableWidget();
myTable->setColumnCount(1);
myTable->setRowCount(5);
myTable->show();
QTableWidgetItem *myTableWidget=new QTableWidgetItem("First Entry ...");
myTable->insertRow(0);
myTable->setItem(0,0,myTableWidget);
QTableWidgetItem *myTableWidget2=new QTableWidgetItem("Second Entry...");
myTable->setItem(1,0,myTableWidget2);
myTable->resizeColumnsToContents();
myTable->setAlternatingRowColors(true);
}
MainWindow::~MainWindow()
{
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Stylesheet widgettest.qss
alternate-background-color: yellow;
background-color: red;
}
QTableWidget {
alternate-background-color: yellow;
background-color: red;
}
To copy to clipboard, switch view to plain text mode
Bookmarks