PDA

View Full Version : QTreeView: How to center a checkbox in a cell



chezifresh
19th December 2008, 01:48
I have a QTreeView with a custom model. In that model I display boolean types with a checkbox using the CheckStateRole. I have nothing in the DisplayRole which basically gives you a checkbox and nothing else in that cell. Does anyone have a good idea of how to get that checkbox to be center aligned in the cell?

Unfortunately the Qt::TextAlignmentRole doesnt affect the checkbox. I suppose its possible to use a proxy style but I have no clue how to correctly implement it. Any ideas? Code? :D

aamer4yu
19th December 2008, 06:05
QItemDelegate::createEditor might help you.

Also search the forums, ther have been threads on similar situations

calmspeaker
19th December 2008, 11:56
QItemDelegate::createEditor might help you.

Also search the forums, ther have been threads on similar situations

I think use QItemDelegate::createEditor is not a convenient way. I search the forums , and get nothing could help. Can you make it more clearly? Thanks in advance!

spirit
19th December 2008, 12:11
you can override


virtual void QItemDelegate::drawCheck ( QPainter * painter, const QStyleOptionViewItem & option, const QRect & rect, Qt::CheckState state ) const

but click on this checkbox remains on old position not, on the center.