0

I want to set the background color of all cell in a QTableView Object using css.

something along the lines of...

ui.tableView->setStyleSheet("QTableView { background-color: red; color: yellow");

Is this possible? If so how would I do it?

andre
  • 7,018
  • 4
  • 43
  • 75

2 Answers2

1

Change the css attribute to "background-color", and then your example looks good to go.

Reference:
http://doc.qt.nokia.com/4.7-snapshot/stylesheet-reference.html

jdi
  • 90,542
  • 19
  • 167
  • 203
  • After correcting the example I gave it still does not work. Also I've been follow that reference all along and it shows (for `QTableView`) how to set the `gridline-color` and the color of the cells when selected. But I'm still left with my original problem here. – andre Jul 12 '12 at 20:07
  • Have you tried setting the stylesheet on your main window, so that it affects all QTableView? – jdi Jul 12 '12 at 20:11
  • The Orginal code words just fine. I was overriding the setting in my Model with the default. Thanks. – andre Jul 12 '12 at 20:18
1

I think the following piece of qss can do the trick:

QTableView::item {
      border: 1px solid #d9d9d9;
     border-top-color: transparent;
     border-bottom-color: transparent;
 }

Most of the qss examples for QTreeView work also for QTableView

http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qtreeview

Uga Buga
  • 1,724
  • 3
  • 19
  • 38