Hi!
I'm working with the QT Example "image viewer". Now I open an image like this:
tr("Open File"), tr("C:"));
if (!fileName.isEmpty()) {
if (image.isNull()) {
tr("Cannot load %1.").arg(fileName));
return;
}
imageLabel
->setPixmap
(QPixmap::fromImage(image
));
}
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));
}
To copy to clipboard, switch view to plain text mode
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?
painter.begin(this);
painter.setBackgroundMode(Qt::TransparentMode);
painter.
setCompositionMode(QPainter::CompositionMode_DestinationOver);
painter.drawEllipse(10,10,10,10);
painter.end();
}
void SubQLabel::paintEvent(QPaintEvent *event){
painter.begin(this);
painter.setBackgroundMode(Qt::TransparentMode);
painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
painter.drawEllipse(10,10,10,10);
painter.end();
}
To copy to clipboard, switch view to plain text mode
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?
Thanks!!!!!
Bookmarks