Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    How to print directly without printer dialog?

    General and Desktop
    2
    6
    2597
    Loading More Posts
    • 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
      mbnoimi last edited by

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

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • M
          mbnoimi last edited by

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

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            @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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • M
              mbnoimi last edited by

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

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post