Results 1 to 7 of 7

Thread: Printing values from QTableWidget???

  1. #1
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Printing values from QTableWidget???

    Hi i am using qtablewidget in my project..it has 10 columns & 5000 rows...i want to print the whole tablewidget... When i use the below code i get a empty pdf for 5000 rows...if i use it for less rows like 50 ,it prints only the visible area of the table widget...
    How to solve this issue?
    Is there any way do display a widget page wise , say 100 rows per page and take printout of 100 rows and print another 100 from 2nd page?
    kindly help
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. printer.setOrientation(QPrinter::Landscape);
    3.  
    4. QPrintDialog dlg(&printer, this);
    5.  
    6. if (dlg.exec() == QDialog::Accepted)
    7. {
    8. // calculate the total width/height table would need without scaling
    9. const int rows = ui->Packet_Info->model()->rowCount();
    10. const int cols = ui->Packet_Info->model()->columnCount();
    11.  
    12. double totalWidth = 0.0;
    13.  
    14. for (int c = 0; c < cols; ++c)
    15. {
    16. totalWidth += ui->Packet_Info->columnWidth(c);
    17. }
    18.  
    19. double totalHeight = ui->Packet_Info->horizontalHeader()->height();
    20.  
    21. for (int r = 0; r < rows; ++r)
    22. {
    23. totalHeight += ui->Packet_Info->rowHeight(r);
    24. }
    25.  
    26.  
    27. // redirect table's painting on a pixmap
    28. QPixmap pixmap(totalWidth, totalHeight );
    29.  
    30. QPainter::setRedirected(ui->Packet_Info->horizontalHeader()->viewport(), &pixmap);
    31. QPainter::setRedirected(ui->Packet_Info->viewport(), &pixmap);
    32.  
    33. QPaintEvent event(QRect(0, 0, totalWidth, totalHeight ));
    34.  
    35. QApplication::sendEvent(ui->Packet_Info->horizontalHeader()->viewport(), &event);
    36. QApplication::sendEvent(ui->Packet_Info->viewport(), &event);
    37.  
    38. QPainter::restoreRedirected(ui->Packet_Info->horizontalHeader()->viewport());
    39. QPainter::restoreRedirected(ui->Packet_Info->viewport());
    40.  
    41.  
    42.  
    43. // print scaled pixmap
    44. QPainter painter(&printer);
    45. painter.scale(4,4);
    46. //painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
    47. painter.drawPixmap(printer.pageRect().topLeft(), pixmap, pixmap.rect());
    48.  
    49. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2012
    Posts
    40
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Printing values from QTableWidget???

    Look at this project http://qt-apps.org/content/show.php/...?content=76616.
    It uses QTableView, but maybe it is useful.

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

    prabhudev (6th August 2012)

  4. #3
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing values from QTableWidget???

    Thanks...I will go through it...Is there any other option coz i am using tablewidget...

  5. #4
    Join Date
    Jul 2012
    Posts
    40
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Printing values from QTableWidget???

    You can do it by your own.
    If you want a good layout I would recommend QTextDocument, QTextTable etc. ....

  6. #5
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing values from QTableWidget???

    Can someone please tell how to display tablewidget in page wise...

  7. #6

    Default Re: Printing values from QTableWidget???

    This works just fine for me. Perhaps your table does not have an item at those coordinates?

  8. #7
    Join Date
    May 2012
    Posts
    33
    Thanks
    9
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing values from QTableWidget???

    http://qt-apps.org/content/show.php/...?content=76616.
    This worked fine...had to change some code in that to use my qtablewidget...
    Thanks Qtonimo

Similar Threads

  1. problem printing a QTableWidget
    By rmagro in forum Qt Programming
    Replies: 5
    Last Post: 11th January 2010, 14:59
  2. Printing Values of the mouse position in a graph
    By soumyadeep_pan in forum Qwt
    Replies: 4
    Last Post: 22nd May 2009, 13:17
  3. Printing and QTableWidget
    By Garfeild in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2008, 18:49
  4. Printing QTableWidget
    By rmagro in forum Qt Programming
    Replies: 21
    Last Post: 27th June 2007, 21:06
  5. experiencing problem at printing out QTableWidget
    By rmagro in forum Qt Programming
    Replies: 9
    Last Post: 27th June 2007, 16:04

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.