[Qt-interest] Alignment in QTableView

Sean Harmer sean.harmer at maps-technology.com
Wed May 26 17:39:54 CEST 2010


On Wednesday 26 May 2010 16:22:49 Yves Bailly wrote:
> Hello list,
> 
> Here's a (probably) basic question, but I really can't find a
> solution. Using a QTableView to display the contents of an
> SQL database (using a QSqlTableModel), I would just want to
> have a right-aligned column... but I just can't find a non-insane
> way of doing this SIMPLE thing...
> 
> Any hint?

First thing that springs to mind is a very simple proxy model that overrides 
the data() function for the Qt::TextAlignmentRole for the column that you wish 
to customise.

Probably best to inherit your proxy model from QSortFilterProxyModel to save 
yourself some headaches.

I agree that this type of presentational customisation should be handled by 
the views rather than the models though. To me, the model data should not 
include things like text colour, alignment etc.

HTH,

Sean



More information about the Qt-interest-old mailing list