Results 1 to 1 of 1

Thread: pyqt print preview QTableView

  1. #1
    Join Date
    Mar 2012
    Posts
    3
    Qt products

    Post pyqt print preview QTableView

    I'm trying to print the contents of a QTableView to the printer . i implement bottom script and it run successfully without any error. but all data are Unusual in printPreview. this is pic from my problem -FOUNTAIN


    Qt Code:
    1. def printTable(self,printer,painter,area):
    2. model = self.model
    3. myTableView = self.view
    4. printer = painter
    5. rows = model.rowCount();
    6. columns = model.columnCount();
    7. totalWidth = 0.0;
    8. totalPageHeight = 0.0;
    9. totalHeight = 0.0;
    10. for c in range(columns):
    11. totalWidth += myTableView.columnWidth(c)
    12.  
    13. for p in range(45):
    14. totalPageHeight += myTableView.rowHeight(p);
    15.  
    16. for r in range(rows):
    17. totalHeight += myTableView.rowHeight(r);
    18.  
    19. xscale = area.width() / totalWidth;
    20. yscale = area.height() / totalHeight;
    21. pscale = area.height() / totalPageHeight;
    22. painter.scale(xscale, pscale);
    23. painter.translate(area.x() + xscale, area.y() + yscale);
    24.  
    25. x=0
    26. #QStyleOptionViewItem option;
    27.  
    28. for r in range(rows):
    29. ++x
    30. for c in range(columns):
    31. idx = model.index(r,c);
    32. option = myTableView.viewOptions();
    33. option.rect = myTableView.visualRect(idx);
    34. if r % 2 == 0:
    35. brush= QtGui.QBrush(QtGui.QColor(220, 220, 220), QtCore.Qt.SolidPattern);
    36. painter.fillRect(option.rect, brush);
    37. myTableView.itemDelegate().paint(painter, option, idx);
    38.  
    39. if (x == 45):
    40. ok = printer.newPage();
    41. x=0;
    42. painter.translate(0, -1350);
    43.  
    44. ####################### Now print Table ######################
    45.  
    46. printer = QtGui.QPrinter()
    47. painter = QtGui.QPainter()
    48. painter.begin(printer )
    49. self.printTable(printer,painter, printer.pageRect())
    To copy to clipboard, switch view to plain text mode 


    if you have any example that can help me please tell me . thank you so much
    Last edited by iraj_jelo; 23rd May 2012 at 09:55.

Similar Threads

  1. New button in PrintPreview
    By febil in forum Qt Programming
    Replies: 4
    Last Post: 16th March 2015, 09:09
  2. freeze first two columns in PyQt(QTableView)
    By ramesh03 in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2013, 12:49
  3. printpreview problem
    By ad3d in forum Newbie
    Replies: 1
    Last Post: 17th April 2012, 08:50
  4. PyQt - QTableView with comboBox
    By elanari in forum Qt Programming
    Replies: 1
    Last Post: 9th May 2011, 14:13
  5. Replies: 1
    Last Post: 4th August 2010, 19:50

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.