QRect myRect(10, 10, 100, 100); // Creating a QRect object myRect.moveTo(50, 50); // Moving the rectangle to a new position
void drawRectangle(QPainter* painter) { QRect rect(100, 100, 200, 200); // Creating a QRect object rect.moveTo(150, 150); // Moving the rectangle to a new position painter->drawRect(rect); // Drawing the rectangle }This code creates a QRect object and then moves it to a new position using the moveTo function. The QPainter class is used to draw the rectangle on the screen. Package library: Qt library written in C++.