PDA

View Full Version : QPainter::drawRect(QRect) suspect height behaviour



Binary91
20th September 2015, 11:37
Hi,

in my QTableWidgetItems, I try to display a list of (3) strings vertically ordered and with a border.

For this border, I'd like to draw the rect in a loop and change its y-coordinate, so the same rect should be painted vertically shifted.

This is my code:

rectStringEvent.setY(rectCell.y() + 20); // position of the first string
rectStringEvent.setHeight(15); // rect height, should not be changed but it does!

for(int i = 0; i < 3; i++)
{
pPainter->drawText(rectStringEvent, listEvents.at(i));
pPainter->drawRect(rectStringEvent);
rectStringEvent.setY(rectStringEvent.y() + 15); // <--- this line is the problem: it also changes the rects height! But why?
}
I figured out that the rect's height is decreased by the number I increase the y-coordinate. I don't understand this behaviour. Why can't I just change the y-coordinate and the rect moves and still has it's prior height?

Thank you in anticipation.
Binary

anda_skoa
20th September 2015, 12:36
You are changing the y-coordinate of the top corners, keeping the bottom corners where they are. So the height shrinks.

What you are looking for is QRect::moveTop().

Cheers,
_

Binary91
20th September 2015, 14:53
Yes, you're right. Thank you, it works.

Greetings