#include#include int main() { QPainter painter; QTransform transform; // Rotate the painter by 45 degrees transform.rotate(45); // Set the transformation for the painter painter.setTransform(transform); // Draw a rectangle QRect rect(10, 10, 100, 100); painter.drawRect(rect); return 0; }
#includeIn this example, we use translate to move the QPainter by (50,50). Then we draw a rectangle at the origin (10,10). The rectangle will be placed 50 pixels to the right and 50 pixels down. Package library: Qt.int main() { QPainter painter; // Translate the painter by (50, 50) painter.setTransform(QTransform().translate(50, 50)); // Draw a rectangle QRect rect(10, 10, 100, 100); painter.drawRect(rect); return 0; }