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. Help with printing
Forum Updated to NodeBB v4.3 + New Features

Help with printing

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 993 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.
  • N Offline
    N Offline
    nen777w
    wrote on last edited by
    #1

    Hi
    Please explain somebody how to print image with the 100% scale.
    For example this code:
    @
    QPixemap pxm = .... //load image from file
    QPrinter printer;
    QPainter painter;
    painter.begin(&printer);
    double xscale = printer.pageRect().width()/double(pxm.width());
    double yscale = printer.pageRect().height()/double(pxm.height());
    double scale = qMin(xscale, yscale);
    painter.scale(scale, scale);
    painter.drawPixmap(0,0, pxm)
    @

    Up-scale image (fit to page) to the page and this result isn't 100% image size.
    If I remove this line:
    @painter.scale(scale, scale);@

    The image will down-scale and this also isn't 100% image size.

    I understand that printer operate in QPrinter::DevicePixel space and this is (usually) a much more than screen space.
    My question is how to calculate relation between QPrinter::DevicePixel and Pixels for calculate correct scale coefficients.
    Thanks.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nen777w
      wrote on last edited by
      #2

      My current solution is:

      @
      QPainter painter;
      painter.begin(&m_current_printer);

      const QPixmap& pxm = ///...pixmap from file

      double prnDPI = m_current_printer.resolution();

      //ANYBODY can explain me why 72 DOI is default dpi for the most popular image editors?
      double inch_w = pxm.width() / 72.;
      double inch_h = pxm.height() / 72.;

      double img_w_pix = inch_w * prnDPI;
      double img_h_pix = inch_h * prnDPI;

      QRectF rc(0,0, img_w_pix, img_h_pix);
      painter.drawPixmap(rc, pxm, QRectF(0,0, pxm.width(),pxm.height()));
      @

      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