how do I rotate text about an arbitrary point?
-
The image is the start of a compass display. It's also my first step into drawing on a QPainter.
The line works fine. It rotates around the center of the image. I would like the text to rotate around the center point as well. As it is, the text is rotating around 0, 0 (upper left corner). The forum won't let me attach the zipped project so here is my paintEvent code. This is a subclass of a QLabel.void AZ_Label::paintEvent(QPaintEvent *ev) { Q_UNUSED(ev); QPainter p(this); p.setPen(QPen(Qt::white, 2)); p.rotate(lineAngle); p.save(); p.translate(translateX, translateY); p.drawText(50, 50, "North"); p.restore(); p.rotate(-lineAngle); p.drawEllipse(xPosition, yPosition, cSize, cSize); line.setAngle(qreal(lineAngle)); p.drawLine(line); emit sigSizechanged(xPosition, yPosition, cSize); }
translateX and translateY are set from a slider on the main window.
-
-
@JonB said in how do I rotate text about an arbitrary point?:
@PsylumDan
Does https://stackoverflow.com/questions/31760995/how-to-set-transform-origin-for-qpainter-in-qt, https://stackoverflow.com/a/46180679 address your issue?Thanks for the reply but no. The line works as expected. It's the text that I'm having trouble with.
-
Hi
Qt is not "holding" the text in its center.
You have to calculate the center.
Please try code here.
https://stackoverflow.com/questions/40300346/qt-rotating-text-around-its-center-point -
@mrjj said in how do I rotate text about an arbitrary point?:
Hi
Qt is not "holding" the text in its center.
You have to calculate the center.
Please try code here.
https://stackoverflow.com/questions/40300346/qt-rotating-text-around-its-center-pointThat's exactly what I needed. Thanks!