Qt: QTableWidget / QTableView alternating row colors in full screen

I have a QTableView containing rows of data from a database. However, setting setAlternatingRowColors (true) only alternates the colors of the rows that have data - the rest of the table is just white, which is not the behavior you expect (look in the bookmarks list of any browser, for example, empty lines alternate colors).

Does anyone know of employment or an alternative to table views provided by Qt? I was looking for stylesheets and delegate elements, the same result.

+6
source share
2 answers

You can override the data() method of your model as follows:

 QVariant MyModel::data(const QModelIndex& index, int role) const { if(role == Qt::BackgroundColorRole) return color; ... } 

It should be possible to do the same with the delegate using setModelData() .

+2
source

Why don't you use Qt QSS for this? It works great. Have a look here: http://www.qtcentre.org/threads/42211-QTableWidget-alternating-background-color?p=263046#post263046

 myTable->setAlternatingRowColors(true); myTable->setStyleSheet("alternate-background-color: yellow;background-color: red;"); 
+1
source

All Articles