Results 1 to 20 of 25

Thread: QTableView printing

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Join Date
    Jan 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView-Printing with grid lines

    {Two posts merged}

    Hi All,

    Iam Jagannath Mandapally

    Hi All,

    My Requirement is Print table , Means Generating .ps file and giving to APS Print but I have some issues.

    1) Preview is not visible on APS Print

    2) Printing table but ignoring some rows

    3) Grid lines are not Printing

    my code is :
    Qt Code:
    1. void TableEditor::printt()
    2. {
    3.  
    4. QPrinter printer(QPrinter::HighResolution);
    5. //printer.setFullPage(true);
    6. //printer.setPageSize(QPrinter::A4);
    7. /*int rightMargin = printer.paperRect().right() - printer.pageRect().right();
    8.  int bottomMargin = printer.paperRect().bottom() - printer.pageRect().bottom();
    9. int leftMargin = printer.paperRect().left() - printer.pageRect().left();
    10. int topMargin = printer.paperRect().top() - printer.pageRect().top();*/ //This is commented
    11. //printer.margins(&topMargin,&leftMargin,&bottomMargin, &rightMargin);
    12.  
    13. printer.setOutputFileName("rtest.ps");
    14. QPrintDialog dlg(&printer, this);
    15. double totalWidth = 0.0;
    16. double totalHeight = 0.0;
    17. double totalPageHeight=0.0;
    18. //QRect area;
    19. if (dlg.exec() == QDialog::Accepted){
    20. const int rows=view->model()->rowCount();
    21. const int cols = view->model()->columnCount();
    22. printf("no of rows\n %d",rows);
    23. printf("\n no of columns %d",cols);
    24. for (int c = 0; c < cols; ++c) {
    25. totalWidth += view->columnWidth(c); }
    26. for(int p=0; p<45; p++) //45
    27. {
    28. totalPageHeight+= view->rowHeight(p);
    29.  
    30.  
    31. }
    32. for (int r = 0; r < rows; ++r)
    33. { totalHeight += view->rowHeight(r); }
    34.  
    35.  
    36. } //if loop ending here
    37.  
    38. QPainter painter(&printer);
    39. //QPainter::setRedirected(view->viewport(), &painter);
    40. //QPaintEvent event(QRect(0, 0, totalWidth, totalHeight));
    41. //view->paintEvent(&event);
    42. //painter.drawLines(0,0,rows,cols);
    43. //QApplication::sendEvent(view->viewport(), &event);
    44. //QPainter::restoreRedirected(view->viewport()); //This is commented for testing row nums
    45. //QPainter painter(&printer);
    46. painter.begin(&printer);
    47. const int rows=view->model()->rowCount();
    48. const int columns=view->model()->columnCount();
    49. printf("The num of rows are %d",rows);
    50. QRect area = printer.paperRect(); // here should be pageRect
    51. const double xscale = area.width() / totalWidth;
    52. const double yscale = area.height() / totalHeight;
    53. const double pscale = area.height() / totalPageHeight;
    54. painter.scale(xscale+9, yscale+9); // With the scaling 3 It is Printing all
    55. //painter.translate(area.x() + xscale, area.y() + pscale); //This is original
    56. painter.translate(area.x() + xscale, area.y() + yscale);
    57. //painter.save(); //commented
    58. int x=0;
    59. //int y=0 ;// This is introduced for the columns
    60. //view->paintEvent(&event);
    61. QPainter paint(this);
    62. paint.setPen(Qt::red);
    63. paint.drawRect(0, 0, 0, 0);
    64.  
    65.  
    66. for (int r=0; r<rows; r++)
    67. {
    68. ++x;
    69.  
    70. for(int c=0; c<columns; c++)
    71. {
    72. //++y;
    73.  
    74.  
    75. /*double xscale = printer.pageRect().width() / width();
    76.   double yscale = printer.pageRect().height() / height();
    77.   double scale = qMin(xscale, yscale);
    78.   QRect rect = painter.viewport( ); */
    79. //QSize size = pixmap.size( );
    80. //size.scale( rect.size( ), Qt::KeepAspectRatio );
    81. //painter.drawLines(0,0,rows,columns);
    82.  
    83.  
    84. QModelIndex idx = view->model()->index(r,c);
    85. option = view->viewOptions();
    86. option.rect =view->visualRect(idx);
    87. view->itemDelegate()->paint(&painter, option, idx);
    88. // painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
    89.  
    90. // painter.drawPixmap((r,c), pixmap, pixmap.rect());
    91.  
    92. // if(page!=printer.numCopies())
    93. } //columns are closed here
    94. if (x==39)
    95. {
    96. printf("This is inside if loop %d:",x);
    97. printer.newPage();
    98. x=0;
    99. //y=0;
    100. painter.translate(0, -1150);
    101. //painter.translate(0,-1000);
    102. //painter.translate(0,-850);
    103. x=0;
    104.  
    105. // page++
    106. //painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
    107.  
    108. //x=0;
    109. painter.save();
    110. painter.restore();
    111.  
    112. // break;
    113. }
    114.  
    115. printf("%d",rows);
    116.  
    117.  
    118. // }
    119. }
    120. painter.end();
    121. system("apsprint rtest.ps");
    122.  
    123.  
    124.  
    125.  
    126. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 6th February 2007 at 17:26. Reason: missing [code] tags

Similar Threads

  1. Set height of QTableView to fit exact number of rows.
    By Ben.Hines in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2019, 01:49
  2. QTableView sorting
    By gabriels in forum Qt Programming
    Replies: 11
    Last Post: 6th October 2010, 17:13
  3. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42
  4. Replies: 0
    Last Post: 28th June 2006, 20:49
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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
  •  
Qt is a trademark of The Qt Company.