PDA

View Full Version : QTreeView Alignment



cydside
15th June 2008, 13:00
Hi to all,
I'm looking for a solution on alignment in a QTreeView. The default alignment is AlignLeft but I need to change it for a column. Does anybody know how to do?

Thanks.

jpn
15th June 2008, 13:19
For the whole view you would simply override QAbstractItemView::viewOptions() but for a certain column you might have to implement a custom delegate, override QAbstractItemDelegate::paint() and adjust QStyleOptionViewItem::displayAlignment when the index points to appropriate column.

wysota
15th June 2008, 13:47
Or you can do it on the model level - simply set appropriate values for Qt::TextAlignmentRole.

cydside
15th June 2008, 14:53
Thanks jpn, I've read the documentation about your hint, it's the right way!
Can you show me an example? if it's not so much trouble...


Or you can do it on the model level - simply set appropriate values for Qt::TextAlignmentRole.

Sorry wysota, where do i have to set the Qt::TextAlignmentRole in a QSqlTableModel?
thanks

jpn
15th June 2008, 15:02
Or you can do it on the model level - simply set appropriate values for Qt::TextAlignmentRole.
Indeed, I forgot there was such role. :)


Sorry wysota, where do i have to set the Qt::TextAlignmentRole in a QSqlTableModel?
thanks
Subclass QSqlTableModel and reimplement data() to return desired alignment for Qt::TextAlignmentRole, otherwise call base class implementation.

cydside
15th June 2008, 15:30
Thanks jpn and wysota your hints are very precious!