QPainter & QPrinter



  • 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 ?


  • Moderators

    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);
    


  • @Chris-Kawa thx :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.