I would like to get a cell/row to look like this in a QTableView:

When running Ubuntu, the QStyledItemDelegate works for both the QTreeView and the QTableView, but on Windows, it only works on QTreeView, and only if I don’t reimplement the paint method.
So my 2 questions are:
How do I get the QStyledItemDelegate to look like the above image in a QTableView?
How do I get the QStyledItemDelegate to look like the above image when reimplementing paint?
The image beside the text is not neccessary. I am just looking for the styled hover and selection box.
Just in case this is needed, my Qt version is 4.7.2.
I finally figured enough of it out.
What I did not solve is why not overriding
QStyledItemDelegate.paint()has a different effect from overriding it like:but that was not part of my question anyway.
What I did solve is how to get the native appearance when painting manually. Previously, when painting the item, I used:
which had the issue of not painting the native focus or selection. I had a look at the method signature of
QApplication.style().drawControl():and noticed the
widgetparameter, and tried passing in aQTreeView. It worked. It does not matter whatQTreeViewis passed, but it makes the view render natively.So in the end, rendering a native
QTableViewis as simple as calling:in the
QStyledItemDelegate‘s paint method.