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. Looking for a tutorial
Forum Updated to NodeBB v4.3 + New Features

Looking for a tutorial

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    Pippin
    wrote on last edited by
    #1

    Hello,

    I'm looking for a nice Qt 5.5 tutorial that would show me how to put different texts with different sizes and different fonts on a QImage via a QPainter. And if possible, a tutorial on how to draw a -justified- text on a QImage.

    I've googled this but I haven't quite found what I needed. I apologize if I missed something obvious.

    Thank you.

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      To create a QPainter that will paint on a QImage simply pass the QImage as the parameter in the QPainter constructor.

      To change font of a QPainter use setFont().

      To draw a justified text use the drawText() method of a QPainter and pass Qt::AlignJustify in the flags argument of the method.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Pippin
        wrote on last edited by
        #3

        Thank you for your help, that works perfectly!

        May I also ask how to "stretch" the height of a text? There is QFont::setStretch(int) but that only works for width, and I would like to amplify the height.

        I've found a workaround with

        QPainterObject.setTransform(QTransform(1.0, 0, 0, factor, 0, 0));

        but that messes with positions. (If I want to draw a text at (100, 100) it will be drawn at (100, 100*factor) instead.)

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can only control the horizontal stretch, but this is enough.
          If you want to make the text stretch lets say 200% vertically then make it 2 times bigger using font.setPointSize(font.pointSize() * 2) and set the stretch to half using font.setStretch(50).

          P 1 Reply Last reply
          1
          • Chris KawaC Chris Kawa

            You can only control the horizontal stretch, but this is enough.
            If you want to make the text stretch lets say 200% vertically then make it 2 times bigger using font.setPointSize(font.pointSize() * 2) and set the stretch to half using font.setStretch(50).

            P Offline
            P Offline
            Pippin
            wrote on last edited by
            #5

            @Chris-Kawa

            Thank you so much!

            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