How to print directly without printer dialog?



  • Hi,

    How can I print an image directly to my printer without showing printer dialog?

    @ QImage img(QString("%1/users/%2.png")
    .arg(qApp->applicationDirPath())
    .arg(userId));
    QPrinter printer;
    printer.setPrinterName("Sony");
    printer.setCopyCount(10);
    QPrintDialog dialog(&printer, this);
    if (dialog.exec()) {
    QPainter painter(&printer);
    QRect rect = painter.viewport();
    QSize size = img.size();
    size.scale(rect.size(), Qt::KeepAspectRatio);
    painter.setViewport(rect.x()+10, rect.y()+10, size.width()-10, size.height()-10);
    painter.setWindow(img.rect());
    painter.drawPixmap(0, 0, QPixmap::fromImage(img));
    }@


  • Lifetime Qt Champion

    Hi,

    If you know which printer you want you can user QPrinterInfo to create your QPrinter object and you should be good to go



  • [quote author="SGaist" date="1411904508"]Hi,

    If you know which printer you want you can user QPrinterInfo to create your QPrinter object and you should be good to go[/quote]

    I know the name of my printer, but how can I print using QPrinterInfo?

    May you please post a snippet?


  • Lifetime Qt Champion

    @QPrinter printer(QPrinterInfo::printerInfo("mycoolprintername"));@

    You should check against the list of available printers provided by QPrinterInfo to be sure the name you have matches those known by the Qt Print System



  • [quote author="SGaist" date="1411936108"]@QPrinter printer(QPrinterInfo::printerInfo("mycoolprintername"));@

    You should check against the list of available printers provided by QPrinterInfo to be sure the name you have matches those known by the Qt Print System[/quote]

    Thank you but how this will help?!!
    My question is very basic and simple... How to print directly without printer dialog?


  • Lifetime Qt Champion

    With that you create the correct printer directly, then you adjust what you want to adjust and your start painting on it, just remove the call to QPrintDialog.


Log in to reply
 

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