Results 1 to 3 of 3

Thread: Print entire QTableWidget

  1. #1
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Print entire QTableWidget

    I need to print an entire table with the table grid. Render only gives the visible part of the table. It will also have to cross multiple pages. It's a table with approximately 360 lines. As a separate issue I also need to be able to copy it to the clipboard but one thing at a time. Right now my focus is on printing the darn thing. ( I kept it clean). I wouldn't mind putting it in a double "for" loop and pull out the data as long as the printed copy is in a table format WITH the grid lines.

    QPrinter printer(QPrinter::HighResolution);
    QPrintDialog dlg_Print(&printer,this);
    dlg_Print.exec();
    QPainter painter;
    painter.begin(&printer);
    double xscale = printer.pageRect().width()/double(ui.m_tbl_AvailableHeaders->width());
    double yscale = printer.pageRect().height()/double(ui.m_tbl_AvailableHeaders->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.m_tbl_AvailableHeaders->render(&painter);

    Thanks for any help anyone out there can give me.

    Tony

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Print entire QTableWidget

    One idea would be to create a QTextDocument and add a table into it.
    Either by using QTextTable or by creating a simple HTML table and let the document parse that.

    Clipboard shouldn't be that hard either.
    Most simple way is probably to create a CSV (comma separate value, optimall separator might differ depending on your data) text and put that up for consumption.
    Alternatively, or even additonally (an application can offer clipboard content in more than one format), as an HTML table.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    TonyInSoMD (7th January 2015)

  4. #3
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Print entire QTableWidget

    Thanks a lot anda_skoa! I followed this link http://www.qtcentre.org/threads/5318...ght=QTextTable and it showed me how to create a table and add it to a document. I never would have found it without your help. Right now I'm going to set it up to print, when I get done with that I'll start working on the clipboard.

    Tony

Similar Threads

  1. QTableWidget Internal Drag/ Drop Entire Row
    By davethomaspilot in forum Newbie
    Replies: 0
    Last Post: 16th December 2012, 01:31
  2. Select entire row in QTableWidget, programmatically
    By MattPhillips in forum Qt Programming
    Replies: 2
    Last Post: 24th November 2009, 15:51
  3. Cancelling Long-running Print/Print Preview
    By ChrisW67 in forum Newbie
    Replies: 4
    Last Post: 17th June 2009, 00:05
  4. Building the entire project
    By vermarajeev in forum Qt Programming
    Replies: 14
    Last Post: 28th February 2007, 04:00
  5. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 19:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.