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. Easiest way to print text with multiple fonts using QPainter?
Qt 6.11 is out! See what's new in the release blog

Easiest way to print text with multiple fonts using QPainter?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.0k Views 1 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.
  • S Offline
    S Offline
    spazvt
    wrote on last edited by
    #1

    I'm using a MainWindow status bar to display a moving status drawing, which is light colored on the left and black on the right side. I'm currently using QPainter::drawText to draw black text on the left side, but now I'd like to print some white text on the right side as well. I was hoping that there would be an overloaded version of drawText() that would allow passing in a font specification, either with QString and QFont as parameters or with QTextItem as the input parameter. However, I don't see one. Instead, font is set for the entire QPainter. So I think my only option is to set the font of QPainter, drawText, then change the font of the QPainter and draw the other text.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Yes, that is indeed how QPainter works. You set a mode, you paint a bit, you change the mode, you paint some more...

      1 Reply Last reply
      0
      • S Offline
        S Offline
        spazvt
        wrote on last edited by
        #3

        Ok, thanks. This method is working fine for me.

        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