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 rotate these text?
Forum Updated to NodeBB v4.3 + New Features

How to rotate these text?

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 632 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.
  • D Offline
    D Offline
    deleted385
    wrote on 15 Nov 2021, 13:16 last edited by
    #1

    Translation works with these:

    void Axis::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){
        painter->setRenderHints(QPainter::Antialiasing);
        painter->setPen(QPen(Qt::gray, 1, Qt::DashLine));
        painter->translate(0, m_rect.height());
        painter->scale(1, -1);
        float space = (m_rect.height() - m_labelHeight) / 5;
        float increment = m_max / 5;
        float start = 0, numStart = 0;
        QFontMetrics fm(painter->font());
        for(int i = 0; i < 6; i++){
            painter->drawLine(0, start, m_rect.width(), start);
            painter->save();
            auto label = QString::number(roundf(numStart));
            painter->translate(0, fm.boundingRect(label).height());
            //painter->scale(1, -1);
            painter->drawText(QPointF(0, start), label);
            painter->restore();
            start += space;
            numStart += increment;
        }
    }
    

    BUT couldn't fix the rotation. Here's how the label looks:

    x1.gif

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 15 Nov 2021, 19:56 last edited by
      #2

      Hi,

      Are looking for QPainter::rotate ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      D 2 Replies Last reply 16 Nov 2021, 01:51
      0
      • S SGaist
        15 Nov 2021, 19:56

        Hi,

        Are looking for QPainter::rotate ?

        D Offline
        D Offline
        deleted385
        wrote on 16 Nov 2021, 01:51 last edited by
        #3

        @SGaist, tried that several times last night but those text remains flipped

        1 Reply Last reply
        0
        • S SGaist
          15 Nov 2021, 19:56

          Hi,

          Are looking for QPainter::rotate ?

          D Offline
          D Offline
          deleted385
          wrote on 16 Nov 2021, 02:38 last edited by
          #4

          @SGaist, that's a crazy equation:

          void Axis::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){
              painter->setRenderHints(QPainter::Antialiasing);
              painter->setPen(QPen(Qt::gray, 1, Qt::DashLine));
              painter->translate(0, m_rect.height());
              painter->scale(1, -1);
              int step = 5;
              float space = (m_rect.height() - m_labelHeight) / step;
              float increment = m_max / step;
              float start = 0, numStart = 0;
              QFontMetrics fm(painter->font());
              for(int i = 0; i < 6; i++){
                  painter->drawLine(0, start, m_rect.width(), start);
                  painter->save();
                  auto label = QString::number(roundf(numStart));
                  painter->scale(1, -1);
                  //painter->translate(0, fm.boundingRect(label).height());
                  painter->drawText(QPointF(0, -m_rect.height() + (step - i) * space + fm.boundingRect(label).height()), label);
                  painter->restore();
                  start += space;
                  numStart += increment;
              }
          }
          

          but works:

          x2.gif

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted385
            wrote on 16 Nov 2021, 03:56 last edited by deleted385
            #5

            Each Bar has its own paint and each of them is a separate GraphicsItem BUT why do they rotate like this:

            cap1.png

            if I uncomment painter->rotate(-15);, in the following block, I get the output shown on the right:

            void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *){
                painter->setRenderHints(QPainter::Antialiasing);
                painter->setBrush(Qt::black);
                painter->setPen(Qt::NoPen);
                painter->translate(0, m_rect.height());
                painter->scale(1.0, -1.0);
                float h1 = m_series.value1 / m_max * (m_rect.height() - m_axisLabelHeight - m_labelHeight);
                float h2 = m_series.value2 / m_max * (m_rect.height() - m_axisLabelHeight - m_labelHeight);
                auto rect = QRectF(m_rect.left(), m_labelHeight, m_rect.width(), h1);
                painter->drawRect(rect);
                painter->setBrush(Qt::gray);
                rect = QRectF(m_rect.left(), m_labelHeight +h1, m_rect.width(), h2);
                painter->drawRect(rect);
                painter->setPen(Qt::gray);
                painter->scale(1, -1);
                //painter->rotate(-15);
                painter->drawText(m_rect.left(), 0, m_series.name);
            }
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 16 Nov 2021, 20:53 last edited by
              #6

              I would add save and restore calls on your QPainter object.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              D 1 Reply Last reply 16 Nov 2021, 21:59
              0
              • S SGaist
                16 Nov 2021, 20:53

                I would add save and restore calls on your QPainter object.

                D Offline
                D Offline
                deleted385
                wrote on 16 Nov 2021, 21:59 last edited by deleted385
                #7

                @SGaist, if I do this:

                ...
                painter->save();
                painter->scale(1, -1);
                painter->rotate(-15);
                painter->drawText(m_rect.left(), 0, m_series.name);
                painter->restore();
                

                or:

                ...
                painter->scale(1, -1);
                painter->save();
                painter->rotate(-15);
                painter->drawText(m_rect.left(), 0, m_series.name);
                painter->restore();
                

                I get same result. Uploaded the project in GitHub.

                eyllanescE 1 Reply Last reply 16 Nov 2021, 22:40
                0
                • D deleted385
                  16 Nov 2021, 21:59

                  @SGaist, if I do this:

                  ...
                  painter->save();
                  painter->scale(1, -1);
                  painter->rotate(-15);
                  painter->drawText(m_rect.left(), 0, m_series.name);
                  painter->restore();
                  

                  or:

                  ...
                  painter->scale(1, -1);
                  painter->save();
                  painter->rotate(-15);
                  painter->drawText(m_rect.left(), 0, m_series.name);
                  painter->restore();
                  

                  I get same result. Uploaded the project in GitHub.

                  eyllanescE Offline
                  eyllanescE Offline
                  eyllanesc
                  wrote on 16 Nov 2021, 22:40 last edited by
                  #8

                  @Emon-Haque The objective of GitHub is not to share zip but to upload all files (.cpp, .h and others). This way it is easier to analyze the code, report issues and send pull requests

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  D 1 Reply Last reply 16 Nov 2021, 23:13
                  1
                  • eyllanescE eyllanesc
                    16 Nov 2021, 22:40

                    @Emon-Haque The objective of GitHub is not to share zip but to upload all files (.cpp, .h and others). This way it is easier to analyze the code, report issues and send pull requests

                    D Offline
                    D Offline
                    deleted385
                    wrote on 16 Nov 2021, 23:13 last edited by deleted385
                    #9

                    @eyllanesc, sometimes, I keep more than one project in one repo, ie. ETL-QuranWords or RentManager, and for that, I think, the .zip approach is the best.

                    Another reason I do this is because I couldn't run my projects (first 2/3 repos) after getting back to windows from linux. I'd uploaded those, with github desktop app, before going to linux from windows.

                    Later I realised that I've to learn the github technology to upload things and maintain repo properly and also realized that all those learnings will serve no other purpose other than sharing/using code in/from a repo and since my .zip approach serves that purpose very well in a compressed way, I upload .zip.

                    eyllanescE 1 Reply Last reply 16 Nov 2021, 23:21
                    0
                    • D deleted385
                      16 Nov 2021, 23:13

                      @eyllanesc, sometimes, I keep more than one project in one repo, ie. ETL-QuranWords or RentManager, and for that, I think, the .zip approach is the best.

                      Another reason I do this is because I couldn't run my projects (first 2/3 repos) after getting back to windows from linux. I'd uploaded those, with github desktop app, before going to linux from windows.

                      Later I realised that I've to learn the github technology to upload things and maintain repo properly and also realized that all those learnings will serve no other purpose other than sharing/using code in/from a repo and since my .zip approach serves that purpose very well in a compressed way, I upload .zip.

                      eyllanescE Offline
                      eyllanescE Offline
                      eyllanesc
                      wrote on 16 Nov 2021, 23:21 last edited by
                      #10

                      @Emon-Haque Your arguments may or may not be valid, but I thought to help you check the repository but having everything in a zip I get discouraged, bye, hopefully someone will help you.

                      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                      1 Reply Last reply
                      0

                      1/10

                      15 Nov 2021, 13:16

                      • Login

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