简体   繁体   中英

QImage overlay with mouse selection

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM