Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Printing QWidget window using python
Forum Updated to NodeBB v4.3 + New Features

Printing QWidget window using python

Scheduled Pinned Locked Moved Solved Language Bindings
python
22 Posts 2 Posters 11.1k 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.
  • mrjjM mrjj

    @khakhil
    HI
    you will need a way to select real printer
    then load the image from file
    and draw onto a painter connected to the selected printer.

    try to play around with this sample
    http://stackoverflow.com/questions/8193920/print-a-text-through-a-printer-using-pyqt4
    its with preview and all so maybe over the top

    here is c++ function that grabs screenshot and print it.
    (thx to @Ni-Sumi)

    void MainWindow::printPage() {
      QPixmap pix = QPixmap::grabWindow(QApplication::desktop()->winId());
      QPrinter printer(QPrinter::HighResolution);
      printer.setOrientation(QPrinter::Landscape);
      QPainter painter;
      painter.begin(&printer);
      double xscale = printer.pageRect().width() / double(pix.width());
      double yscale = printer.pageRect().height() / double(pix.height());
      double scale = qMin(xscale, yscale);
      painter.translate(printer.paperRect().x() + printer.pageRect().width() / 2,
                        printer.paperRect().y() + printer.pageRect().height() / 2);
      painter.scale(scale, scale);
      painter.translate(-width() / 2, -height() / 2);
      painter.drawPixmap(0, 0, pix);
      painter.end();
    }
    

    I assume u can read enough to translate to py. :)

    khakhilK Offline
    khakhilK Offline
    khakhil
    wrote on last edited by
    #21

    thanks @mrjj
    I wll try it later
    you saved my life :)

    mrjjM 1 Reply Last reply
    0
    • khakhilK khakhil

      thanks @mrjj
      I wll try it later
      you saved my life :)

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #22

      @khakhil
      hehe super :)
      Good work.
      Im complete python noob but syntax is somewhat the same :)

      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