QPainter painter(this); painter.translate(100,100); // move the origin to (100,100) painter.rotate(45); // rotate the coordinate system by 45 degrees painter.drawRect(-50,-50,100,100); // draw a rectangle centered at the origin
QPainter painter(this); painter.translate(100,100); painter.rotate(45); painter.setFont(QFont("Arial", 20)); painter.drawText(0,0, "Hello World!");This code example is similar to the previous one, but instead of drawing a rectangle, the drawText() function is used to draw the text "Hello World!" centered at the origin. The text is rotated 45 degrees around the (100,100) point. The QPainter class is part of the Qt libraries.