QPainter painter(this); QRect rect(50, 50, 100, 100); painter.setClipRect(rect); painter.drawImage(rect, QImage("image.jpg"));
QPainter painter(this); QRect rect(50, 50, 100, 100); painter.setClipRect(rect); painter.drawEllipse(rect);In this example, we again create a QPainter object and set its clip region to a rectangle with coordinates (50, 50) and dimensions of 100 by 100 pixels. We then draw an ellipse using the drawEllipse method, which will only be visible within the clip region specified by setClipRect. Package library: Qt