PDA

View Full Version : QGraphicsTextItem Paint()



goldhappywang
18th September 2009, 09:42
hello, I overrided the paint() in the class QGraphicsTextItem
the Code


void Tag::paint(QPainter *item,const QStyleOptionGraphicsItem *option,QWidget *widget)
{
QRectF rect = boundingRect();
item->drawRect(rect);
}


but the rect only display the top and left frame lines
the bottom and right frame lines disappear

thanks

wysota
18th September 2009, 10:13
That's perfectly normal. Read QRect docs about the right() and bottom() members.

scascio
18th September 2009, 10:22
Why is it perfeclty normal? The painter cannot draw it correctly?

Isn't it a question of antialiasing?

goldhappywang
18th September 2009, 10:46
That's OK


rect.setBottomRight(QPointF(rect.x() +100, rect.y()+100));


thanks a lot!

I have another problem, how to change the line space?

wysota
18th September 2009, 12:11
Why is it perfeclty normal? The painter cannot draw it correctly?

Isn't it a question of antialiasing?

It's a question of interpreting QRect. For historical reasons its bottom and right values are decreased by 1. Antialiasing is another thing but GV should compensate for it automatically.

Scorp2us
18th September 2009, 16:39
A box of height and width of 40 at 0,0 takes pixels 0-39 to draw. Now, if you draw a box that fits in that, and you measure, you'll get pixels 1-38 as the difference between the lines. This creates a problem, because your drawn with is no where near the 40 width your rect indicated. What you have to do is pic the next-highest pixel. So you end up drawing on 0 and 40. But the 40th pixel is clipped. I've seen this done in many different packages and it is "right".