Question

How to highlight the pixels in a QImage to highlight or draw a overlay on the pixels which user selected using mouse. I just want to know how i can specify the particular area.

Ex: With a 400x400 QImage data how i can increase or decrease the pixel intensity or overlap an image on top of it where the user selected.

Était-ce utile?

La solution

You can involve QPainter (please refer to the documentation) to draw over your QImage. It allows drawing another images, rectangles, lines etc.

void View::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);

    // Draws your original image.
    painter.drawImage(0, 0, myImage);

    // Draws a blue rectangle over the image.
    QPen rectPen(Qt::blue);
    rectPen.setStyle(Qt::DashLine);
    painter.setPen(rectPen);
    painter.drawRect(0, 0, 100, 100);
    [..]
}

You can maintain your mouse clicks and movement and draw corresponding stuff in paint event handler.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top