tags:

views:

574

answers:

1

Hi,

I'm attempting to use Qt stylesheets to style a reasonably complex UI. So far things are going reasonably well, but I'm running into a difficulty:

How can I work out what widget name I should be targeting for a particular part of a UI? For example, if I want to change the font size in the cells of a QTableView, do I write a style that targets QTableView? or perhaps QAbstractScrollArea? or perhaps QAbstractitemDelegate? As it turns out none of these seem to work - I assume this can be done, but it's a case of working out what the magic combination of widgets is to target the right part of the UI.

The style sheet guide helps somewhat, but seems to be missing a lot of information - the example for customising QTableView only mentions customising the cell background colour, and does not mention changing font colour, size, face, grid lines etc.

Am i missing something here? Perhaps Using stylesheets is the wrong way to go? I certainly hope not, since the alternative (deriving from QStyle) seems much more complicated.

Cheers,

+2  A: 

Rendering of items in an item view is done by the delegate. Since Qt 4.4, the built-in item views use a style-able delegate implementation by default (see this blog post), but it seems that you want more control that it allows you.

In that case, make sure that your model's data() method returns proper values for the appearance related ItemDataRoles (I think that Qt::FontRole will be especially of interest to you). If that is not enough, or if it's not possible, you should subclass QStyledItemDelegate and reimplement its paint() method.

As to grid lines, QTableView has the gridStyle property.

IgKh
Hi,That blog post helps a lot however, the example they're using changes the background colour and border - I seem unable to change the row height or font size.
Thomi
Thomi: Like I motioned in the answer, those things are not (as far as I know) style-able. Make sure your model returns a QFont instance as data for the FontRole, and a QSize instance as data for the SizeHintRole
IgKh