#include#include int main() { QRectF rect(0, 0, 100, 100); QRectF translatedRect = rect.translated(50, 50); std::cout << "Original Rect: " << rect.x() << "," << rect.y() << "," << rect.width() << "," << rect.height() << std::endl; std::cout << "Translated Rect: " << translatedRect.x() << "," << translatedRect.y() << "," << translatedRect.width() << "," << translatedRect.height() << std::endl; return 0; }
#includeIn this example, we create a pair of QRectF objects as in the previous example, but instead of outputting their coordinates, we create a QPainter object and draw both rectangles on the screen using its drawRect() method. This requires including the QPainter header file and linking against the QtGui library.#include int main() { QRectF rect(0, 0, 100, 100); QRectF translatedRect = rect.translated(50, 50); QPainter painter; painter.drawRect(rect); painter.drawRect(translatedRect); return 0; }