Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: QTableView printing

  1. #21
    Join Date
    Jan 2007
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView printing

    Hi Jacek,

    Thank U very much , I need solution desparately

    BR
    Jagannath

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView printing

    First try cleaning your code, because it's unreadable.

    Maybe you should consider creating a report in HTML using QTextDocument?

  3. #23
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTableView-Printing with grid lines

    This was very helpful to my Problem with Printing from QTableModel but I have encountered some hick ups

    when i print a cell i use this
    Qt Code:
    1. //i have initialized my painter like this
    2. QPainter painter (printer);
    3. painter.scale(idealXScale, idealYScale);
    4. painter.setClipping(true);
    5. qDebug() << "hasClippings = "<< painter.hasClipping(); // this will always give me false
    To copy to clipboard, switch view to plain text mode 

    then i pass painter on to print a page

    Qt Code:
    1. for (int r = info.startRow; r <= info.endRow; ++r)
    2. {
    3. for (int c = info.startCol; c <= info.endCol; ++c)
    4. {
    5. QModelIndex idx = model()->index(r,c);
    6. QStyleOptionViewItem option = viewOptions();
    7. option.rect = visualRect(idx);
    8. if (r % 2 == 0)
    9. {
    10. QBrush brush(QColor(220, 220, 220), Qt::SolidPattern);
    11. painter.fillRect(option.rect, brush);
    12. }
    13.  
    14. itemDelegate()->paint(&painter, option, idx);
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    now when the cell's content is clipped ( content not fully shown in the rect or maybe elided) then somehow the text will be printed but text is too big.

    picture speaks a thousand words
    Attached Images Attached Images

  4. #24
    Join Date
    Mar 2012
    Posts
    3
    Qt products

    Question Re: QTableView printing

    hi friend . how i do translate this part code from c++ to python?


    for (int c = 0; c < cols; ++c)
    {
    QModelIndex idx = model()->index(r, c);
    QStyleOptionViewItem option = viewOptions();
    option.rect = visualRect(idx);
    itemDelegate()->paint(painter, option, idx);
    }


  5. #25
    Join Date
    Mar 2012
    Posts
    3
    Qt products

    Default Re: QTableView printing


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.