PDA

View Full Version : Insert/Delete points over image



sergio87
17th May 2011, 12:52
Hi!

I'm working with the QT Example "image viewer". Now I open an image like this:


QString fileName = QFileDialog::getOpenFileName(this,
tr("Open File"), tr("C:"));
if (!fileName.isEmpty()) {
QImage image(fileName);
if (image.isNull()) {
QMessageBox::information(this, tr("Image Viewer"),
tr("Cannot load %1.").arg(fileName));
return;
}
imageLabel->setPixmap(QPixmap::fromImage(image));
}
imageLabel is QLabel.

Well, I want to draw something (circle, ellipse...) on the image every time I clicked (at mouse position). I have the mouse position (x, y). But I can't draw nothing. I would still see the image.

What I've done?

void SubQLabel::paintEvent(QPaintEvent *event){
painter.begin(this);
painter.setBackgroundMode(Qt::TransparentMode);
painter.setCompositionMode(QPainter::CompositionMo de_DestinationOver);
painter.drawEllipse(10,10,10,10);
painter.end();
}
I subclased the QLabel I I override the paintEvent. But the image dissapears and it shows the Ellipse with white background.

I would like to put a lot of points and delete this points on image.

How can I do that? :confused:

Thanks!!!!! :D:D:D

high_flyer
17th May 2011, 13:14
But the image dissapears and it shows the Ellipse with white background.
Because now the paintEvent() is only painting the ellipse.
Add QLabel::paintEvent(event); before your drawing code.

pkj
17th May 2011, 13:24
try calling QLabel::Paint at the beginning of ur subclassed method

sergio87
18th May 2011, 07:37
Thanks!!! :D

It works!!. I'm going to try if I can draw an ellipse and then detele it. The code is:


void SubQLabel::paintEvent(QPaintEvent *event){
QLabel::paintEvent(event);
painter.begin(this);
painter.drawEllipse(10,10,10,10);
painter.end();
}
Painter is QPainter.

Also I'm going to try how can I scale the ellipse at the same time I scale the image.

Thank you very much!!! :D