PDA

View Full Version : I am having a minor problem with my code.



ayanda83
5th April 2015, 01:50
Please see code below. I've got an 842 x595 image and I want to split it into two images of size 421x595 each, hence I used the copy function. The copying works perfect and I am able the display the first copy of my Image in the view. Please see the attached image and the output to my program.1105711058

void Page::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setBrush(Qt::NoBrush);

QImage image(directory);
QImage frontPageBackground = image.copy(QRect(422,0,image.rect().width(),image. rect().height()));
QImage backPageBackground = image.copy(QRect(0,0,image.rect().width()/2, image.rect().height()));

painter->drawImage(rect, backPageBackground );
}

The problem comes when I want to display the second piece of the image and suddenly my scene looks like this.11059 Please help guys. I know this is a minor problem but I just don't get why this is happening.

jefftee
5th April 2015, 04:07
What is the width of your rect variable you're passing to QPainter::drawImage?

ayanda83
5th April 2015, 08:45
its the width of the image itself.

anda_skoa
5th April 2015, 09:03
Have you tried copying the first image also with half width?
Line 6 of your snippet above uses rect.width() for the third argument of copy()

Cheers,
_

jefftee
5th April 2015, 17:17
It doesn't look like line 6 for frontPageBackground is used at all.


its the width of the image itself.
The way I read it, you're painting only half the image. You create backPageBackground by copying half of the image's width, then you paint it in a rect that is the full size of the original image?

ayanda83
5th April 2015, 18:06
Have you tried copying the first image also with half width?
Line 6 of your snippet above uses rect.width() for the third argument of copy()

Cheers,
_

Thank you. I knew that this was a small error. thank you for pointing it out to me.