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/export a QTreeWidget content?
Qt 6.11 is out! See what's new in the release blog

How to print/export a QTreeWidget content?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Assuming I have a QTreeWidget like that

    !http://i.stack.imgur.com/A1jUW.png(Print QTreeWidget)!

    I tried this code to Print/Export this QTreeWidget to a file (The name of this QTreeWidget is trvListVehicle)

    @
    QPrinter printer(QPrinter::HighResolution);
    QPainter painter;
    painter.begin(&printer);

    double xscale = printer.pageRect().width() / double(ui->trvListVehicle->width());
    double yscale = printer.pageRect().height() / double(ui->trvListVehicle->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);

    ui->trvListVehicle->render(&painter);
    @

    The program shows Print dialog for me to choose printer machine. After printing completely, I got a blank page. The page didn't contain any content.

    Could you help me?

    Thanks!

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Never used the QPrinter myself before, but if I read the doc correct you should use the QPainter::begin() function to prepare the printer for writing to the page. When a new page is needed a QPainter::newPage().
      That might help for the actual printing.

      Greetz, Jeroen

      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