How to print text at similar horizontal interval same rotation angle (Solved)
-
I want to print several text at similar horizontal interval same rotation angle.
But i tried many attempt, all the text is consolidated and rotated together at one angle.QPen myPen;
QFont myFont;
QPointF m_pos;
painter.rotate(20);m_pos = QPointF(20,50);
qreal dx=80;
qreal dy=0;QPainterPath myPath;
m_pos += QPointF(dx,dy);
myPath.addText(m_pos,font, tr("Station1"));
m_pos += QPointF(dx,dy);
myPath.addText(m_pos,font, tr("Station2"));
m_pos += QPointF(dx,dy);
myPath.addText(m_pos,font, tr("Station3"));
painter.drawPath(myPath); -
Hi
If it must be Paths , my answer is no good but here is how
to draw it like I assume you mean: (like a overview for train departures )void drawRotatedText(QPainter *painter, float degrees, int x, int y, const QString &text) { painter->save(); painter->translate(x, y); painter->rotate(degrees); painter->drawText(0, 0, text); painter->restore(); } void MyWidget:paintEvent ( QPaintEvent* event ) { QPainter painter ( this ); QFont font; font.setPixelSize(12); int dx=50; int y=0; QString str; painter.rotate(0); for(int i = 1; i < 10; i++){ str = "Station " + QString::number(i); painter.setFont(font); drawRotatedText(&painter, 20, y+dx, 100, str); y+=dx; }