// Create a rectangle QRect rect(0, 0, 100, 100); // Move the rectangle to a new position rect.moveTop(50); // Print the new rectangle coordinates qDebug() << "Top edge of the rectangle is at position:" << rect.top();
// Create a rectangle QRect rect(0, 0, 100, 100); // Move the rectangle to a new position using an animation over 1 second QPropertyAnimation *animation = new QPropertyAnimation(&rect, "top"); animation->setDuration(1000); animation->setStartValue(0); animation->setEndValue(50); animation->start(); // Print the new rectangle coordinates after the animation finished connect(animation, &QPropertyAnimation::finished, [&]() { qDebug() << "Top edge of the rectangle is at position:" << rect.top(); });In both examples, we create a QRect object with dimensions (0, 0, 100, 100) which means it starts at position (0, 0) with a width and height of 100 pixels. We then use the ```moveTop``` method to move the rectangle to a new position by changing its top edge position. The first example simply moves the rectangle to a position of 50 pixels from the top edge of the screen. The second example animates the movement of the rectangle using a QPropertyAnimation object which changes the top edge position over 1 second from 0 to 50 pixels. We then print the new position of the top edge of the rectangle after the animation has finished. The QRect moveTop method is a part of the Qt library which is included in the Qt Core module.