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. text in paintevent

text in paintevent

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.1k 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.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    Hi,

    alt text

    I have overlay text, aligned , can i have the overlay text aligned one by one vertically in paintevent.

            painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString);
            painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring);
            painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);
    

    Thanks,

    Pradeep Kumar
    Qt,QML Developer

    J.HilkJ jsulmJ 2 Replies Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      Hi,

      alt text

      I have overlay text, aligned , can i have the overlay text aligned one by one vertically in paintevent.

              painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString);
              painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring);
              painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);
      

      Thanks,

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @Pradeep-Kumar

      hi,

      seems like if you add a new line \n QPainter actually draws a new line. Take a look at the docu here

      In case you want to use multiple drawTexts, you'll have to add an Vertical offset to the rect , of at least the average Char height, instead of a horizontal offset but that seems kind of obvious!?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        I used \n , but u specified vertical offset , how can i achieve ,?.

        Thanks,

        Pradeep Kumar
        Qt,QML Developer

        J.HilkJ 1 Reply Last reply
        0
        • Pradeep KumarP Pradeep Kumar

          I used \n , but u specified vertical offset , how can i achieve ,?.

          Thanks,

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Pradeep-Kumar

          QFontMetrics metrix(painter->font());
          int hOffset = metrix.height();
          
          painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString);
          rect = rect.setY(rect.y()+hOffset);
          painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring);
          rect = rect.setY(rect.y()+hOffset);
          painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          0
          • Pradeep KumarP Pradeep Kumar

            Hi,

            alt text

            I have overlay text, aligned , can i have the overlay text aligned one by one vertically in paintevent.

                    painter.drawText(rect,Qt::AlignBottom | Qt::AlignLeft,StartString);
                    painter.drawText(rect,Qt::AlignBottom | Qt::AlignCenter,Centerstring);
                    painter.drawText(rect,Qt::AlignBottom | Qt::AlignRight,EndString);
            

            Thanks,

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Pradeep-Kumar I'm not sure I understand your question. But isn't Qt::AlignVCenter what you're looking for?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • Venkatesh VV Offline
              Venkatesh VV Offline
              Venkatesh V
              wrote on last edited by
              #6

              Hi @Pradeep-Kumar ,

              Try This,

              QRect firstTextrect(0,0,rect.width(),rect.heght()/3);
              QRect secTextrect(0,firstTextrect.bottomLeft(),rect.width(),rect.heght()/3);
              QRect ThirdTextrect(0,secTextrect.bottomLeft(),rect.width(),rect.heght()/3);

              painter.drawText(firstTextrect,Qt::AlignLeft,StartString);
              painter.drawText(secTextrectr,Qt::AlignLeft,Centerstring);
              painter.drawText(ThirdTextrect,Qt::AlignLeft,EndString);

              1 Reply Last reply
              2

              • Login

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