PDA

View Full Version : Setting margin for drawText



waynew
6th September 2010, 17:23
I have a custom item delegate to color tableview rows.
It works fine with one exception - the text is drawn with no margin.
The standard delegate sets a small margin to the left of the text it draws.
I have looked at the Trolls source for the standard delegate but with my limited skills, I can't see how to achieve this in my code.
This is the line that draws the text:

painter->drawText(option.rect, Qt::AlignJustify, index.data().toString());

Any ideas are appreciated....

tbscope
6th September 2010, 17:35
Change option.rect

It's a rectangle that defines the place where the text is drawn. Just shift it a few pixels.

waynew
6th September 2010, 17:58
Thanks tbscope - it's perfect now.



QRect rect = option.rect;
rect = rect.adjusted(3, 0, 0, 0);
painter->drawText(rect, Qt::AlignJustify, index.data().toString());