Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QPainter & QPrinter
Forum Updated to NodeBB v4.3 + New Features

QPainter & QPrinter

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
3 Posts 2 Posters 763 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.
  • M Offline
    M Offline
    MrLibya
    wrote on last edited by
    #1

    Hello
    The software that I'm making is POS , so now i got litile problem with the printer
    I want make the QPainter draw text on the center , but the problem is with the points ( it will have different point with different paper size)

    int height = printer->heightMM();
        int width = printer->widthMM();
        QPainter painter(printer); // create a painter which will paint 'on printer'.
        painter.setPen(Qt::blue);
        painter.setFont(QFont("Tahoma",16));
        painter.drawText(QPoint(height +130, width),ConfigDialog::_shopName);
    

    So this code wont really help , so how i can make it draw text on the top middle , so how i do it ?

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

      Use drawText() overload that uses a rectangle, not point and specify alignment in that rectangle to be top and centered horizontally:

      int height = printer.height();
      int width = printer.width();
      
      painter.setPen(Qt::blue);
      painter.setFont(QFont("Tahoma",16));
      painter.drawText(QRect(0, 0, width, height), Qt::AlignTop | Qt::AlignHCenter, ConfigDialog::_shopName);
      
      1 Reply Last reply
      2
      • M Offline
        M Offline
        MrLibya
        wrote on last edited by
        #3

        @Chris-Kawa thx :)

        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