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 directly without printer dialog?

How to print directly without printer dialog?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.0k 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
    mbnoimi
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        mbnoimi
        wrote on last edited by
        #3

        [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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          0
          • M Offline
            M Offline
            mbnoimi
            wrote on last edited by
            #5

            [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
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved