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 with the right font
Forum Updated to NodeBB v4.3 + New Features

How to print text with the right font

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 343 Views
  • 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.
  • M Offline
    M Offline
    Mihaill
    wrote on last edited by
    #1

    Hi!
    How to print text with the right font?
    If I do so, the font does not change.

        QString testText = "test1";
    
        int id = QFontDatabase::addApplicationFont(":/fonts/code128.ttf"); 
        QString family = QFontDatabase::applicationFontFamilies(id).at(0); 
        QFont font(family);  
        font.setPixelSize(30);
    
        QStaticText testStaticText;
        testStaticText.setText(testText);
        QTransform  transform;
        testStaticText.prepare(transform,font);
    
        QPrinter printer;
    
        QPainter painter;
        painter.begin(&printer);
        painter.drawStaticText(0, 0, testStaticText);
        painter.end();
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mihaill
      wrote on last edited by
      #2

      it is work

          painter.setFont(font);
          painter.drawText(0, 0, 200, 30, Qt::AlignLeft|Qt::AlignTop, testText); //int x, int y, int width, int height,
      
      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