You could use QLabel for showing the image, then use custom painting to draw the frame and for example a transparent gray layer over the part which should be "hazy".
{
// let the label paint the image (setPixmap()) underneath
// init painter for custom drawing
// draw a frame over the image (black, 2 pixels wide)
QRect frameRect
(0,
0,
350,
350);
painter.
setPen(QPen(Qt
::black,
2));
painter.setBrush(Qt::NoBrush);
painter.drawRect(frameRect);
// calc clip region
clipRegion = clipRegion.subtract(frameRect);
painter.setClipRegion(clipRegion);
// draw a gray layour over the rest to make it look hazy
painter.setPen(Qt::NoPen);
hazyColor.setAlpha(100);
painter.
setBrush(QBrush(hazyColor
));
painter.drawRect(rect());
}
void ImageLabel::paintEvent(QPaintEvent* e)
{
// let the label paint the image (setPixmap()) underneath
QLabel::paintEvent(e);
// init painter for custom drawing
QPainter painter(this);
// draw a frame over the image (black, 2 pixels wide)
QRect frameRect(0, 0, 350, 350);
painter.setPen(QPen(Qt::black, 2));
painter.setBrush(Qt::NoBrush);
painter.drawRect(frameRect);
// calc clip region
QRegion clipRegion(rect());
clipRegion = clipRegion.subtract(frameRect);
painter.setClipRegion(clipRegion);
// draw a gray layour over the rest to make it look hazy
painter.setPen(Qt::NoPen);
QColor hazyColor(QColor(Qt::gray));
hazyColor.setAlpha(100);
painter.setBrush(QBrush(hazyColor));
painter.drawRect(rect());
}
To copy to clipboard, switch view to plain text mode
PS. above code is written on the fly and is not guaranteed to work 100%
Bookmarks