How can I change QTableView's color of the area that doesn't have cells on it?
-
[quote author="Edico" date="1314534038"]Volker, I've tried like that but it also does changing the cells color.[/quote]
That's correct. The background color is behind the cells and behind the widget :-(
What you could do is use a style sheet and set the background color of the table there and another background color for the cells. -
I didn't made it even with style sheets. I've reached doing something like that:
@
QTableView {
alternate-background-color: blue;
background: red
}QTableView::item:selected {
background-color: green
}QTableView::item {
background-color: white
}
@All items are white with no alternate row colors.
-
I can reproduce this problem here and it looks like a bug. When setting the background-color for the item in addition to the background -color and the alternate-background-color for the table, then the alternate-background-color will be ignored. I suggest you report this issue in "Jira":https://bugreports.qt.nokia.com//secure/Dashboard.jspa.
-
if you use a proxy model, the proxy models data method is called for each data query instead of the methods of the original model. This then calls the original (source) model. So you can do everything you want there, like changing backroundColor via the Qt::BackgroundRole. IMHO ProxyModels are easier then derived SQL models ;-)
-
Yes, you can create your custom ProxyModel by sublcassing QSortFilterProxyModel and reimplementing the data() method. From there, you can do everything you want, like Gerolf said.
Finally, you just set the sourceModel of your ProxyModel, and it should work :)
-
Yes. If you were using 4.8, I would suggest you use -QIdentityModel- [[doc:QIdentityProxyModel]] as your base class, but if you are still on 4.7, use [[doc:QSortFilterProxyModel]] instead. You only need to reimplement the data() method. In that method, you only need to implement the case where the Qt::BackgroundRole is requested. Based on the row number (odd or even), you can return a different color. For all other cases, you get the parent QModelIndex by calling mapToSource() on the model index, and then return the result of calling the data() method on the source model with the same role and the model index you just mapped.