Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to print text at similar horizontal interval same rotation angle (Solved)
Forum Updated to NodeBB v4.3 + New Features

How to print text at similar horizontal interval same rotation angle (Solved)

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 731 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #1

    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);

    H 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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;
          }
      

      http://postimg.org/image/6fgl0x5i7/

      1 Reply Last reply
      0
      • H houmingc

        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);

        H Offline
        H Offline
        houmingc
        wrote on last edited by
        #3

        Awesome, thanks.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved