PDA

View Full Version : QPainter Fails to Paint



gga96
6th April 2016, 00:24
Good Morning All,

My app deals with burrowing down to the R G B pixel data in successive video frames. The frame analysis takes place in a dialog where method ShowFrame renders a zoomed QPixmap to screen.

My problem is I cannot get the QPainter to zoom the pixmap.


void IconDialog::ShowFrame(QString aFrameNm, int Zoom)
{
QGraphicsPixmapItem *item;
FrameNm = aFrameNm;
scene->clear();
Frame.load(aFrameNm);
scene->setSceneRect(Frame.rect());
QPixmap pixmap = QPixmap::fromImage(Frame);
if (Zoom > 1) {
QRectF sr = pixmap.rect(); //source rectangle
int w = qRound(sr.width()/Zoom);
int h = qRound(sr.height()/Zoom);
QRectF tr; //target rectangle
tr.setX(sr.width()-w);
tr.setY(sr.height()-h);
tr.setWidth(w);
tr.setHeight(h);
QPainter p;
if (p.begin(this)) {
p.drawPixmap(tr, pixmap, sr);
p.end();
}
else {
QMessageBox::information(0, "Error IconDialog", "Statement p.begin(this) failed, I don't know why.");
}
}
item = new QGraphicsPixmapItem(pixmap);
scene->addItem(item);
ui->FrameGV->show();
}

What ever I try results in activating the QMessageBox, I cannot find a "last error" or a reason for failure.
I have followed the usual procedures to resolve the issue but without success.

I believe my code is at fault, I have missed something, but what?

Hope you can help.

Thank you.

Regards
Glen

gga96
6th April 2016, 05:28
I have found the errors I had made in the posted code (nothing like a good nights sleep).

Correction 1: Edit line 19 to read "if (p.begin(&pixmap)) {" that got painter working which exposed another error with Source and Target rectangles doing the wrong thing.

Correction2: Transpose the use of "sr" and "tr".

Sorry to have troubled you.

Regards
Glen

PS How do I mark this thread SOLVED?