Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Printing QTableWidget

  1. #1
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Printing QTableWidget

    Hi all guys,

    I know there was a discussion in this forum in the past,
    but even if I put the best of my attention I was not able to
    get the goal

    Can someone help?

    Thank you in advance.

    Roberto

  2. #2
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question qtableWidget

    Hi all,

    How to print aQTableWidget?
    I know there was a discussion in this forum in the past,
    but even if I put the best of my attention I was not able to
    get the goal

    If someone has example code please can help?

    Thank you in advance.

    Roberto

  3. #3
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QtableWidget

    Hi

    about printing a QtableWidget,
    I tried again the code suggested once by JPN,
    but no success..

    Attached you will find what I get

    Any clue? any idead..?
    What could be wrong?

    Thank you,

    Roberto
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtableWidget

    Hi. First of all, please don't start multiple threads on the same subject.
    Quote Originally Posted by rmagro View Post
    What could be wrong?
    You might want to adjust the scaling a bit. Looks like the content is scaled to fit the page.
    J-P Nurmi

  5. #5
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtableWidget

    Thanks JPN

    You might want to adjust the scaling a bit. Looks like the content is scaled to fit the page.[/QUOTE]

    Which line of your suggested code should I modify?

    regards

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtableWidget

    Quote Originally Posted by rmagro View Post
    Which line of your suggested code should I modify?
    Sorry, but which code snippet are you referring to?
    J-P Nurmi

  7. #7
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtableWidget

    Oh sorry..

    this is the link you posted once..

    http://www.qtcentre.org/forum/f-qt-p...g-3796.html#10

    ..should I add something??

    If so how to complete it?

    Thanka a lot

    Roby

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtableWidget

    It depends how you want it to be. Maybe drawing it without scaling suits your needs:
    Qt Code:
    1. // painter.drawPixmap(printer.pageRect(), pixmap, pixmap.rect());
    2. painter.drawPixmap(printer.pageRect().topLeft(), pixmap);
    To copy to clipboard, switch view to plain text mode 
    Or alternatively use HTML and QTextDocument as suggested by Jacek at the end of the thread.
    J-P Nurmi

  9. #9
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtableWidget

    JPN,

    following your suggestion it Prints the entire table ..in the top left corner of the page..

    only a problem...

    the table is extremely little...I can't even see it ..

    How come?

    is there a scaling problem?

    Roby

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtableWidget

    Give it a try with QPrinter::ScreenResolution. Presumably the another option is to scale according to used resolution in case it doesn't look good enough.
    J-P Nurmi

  11. #11
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtableWidget

    Indeed now it look grater but not all the columns fit on the page..

    "Presumably the another option is to scale according to used resolution in case it doesn't look good enough"

    Can you show me how to do it?

  12. #12
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtableWidget

    I tried the following:

    QPrinter printer;
    int dpi = printer.resolution();
    printer.setResolution(dpi);

    but it doesn't change the fact that the table is not entirely printed..

    Roby

  13. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtableWidget

    Quote Originally Posted by rmagro View Post
    Qt Code:
    1. int dpi = printer.resolution();
    2. printer.setResolution(dpi);
    To copy to clipboard, switch view to plain text mode 
    I'm sorry to say but this does nothing at all. One option is to go with QPainter::scale(). A scale factor of 0.5 makes it half of the original size, 2 makes it double.
    J-P Nurmi

  14. #14
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing QTableWidget

    Many thanks JPN
    for your help!

    I tried what you suggested but it does not look good yet..

    The problem is that if I choose "painter.scale(0.5,0.5); "
    it prints the entire table but che characters inside the cells
    are not visible because of bad resolution(maybe too small)

    Further suggestions?

    Thank again

    Roby

  15. #15
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing QTableWidget

    I rolled back to
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    To copy to clipboard, switch view to plain text mode 

    and I added

    Qt Code:
    1. printer.setOrientation(QPrinter::Landscape);
    2. painter.scale(4,4);
    To copy to clipboard, switch view to plain text mode 

    Now it fits the page...

    but hey ...where is table bar titles??

    How to get it ??

    Thank for your reply

    Roberto.

  16. #16
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing QTableWidget

    JPN,

    I tried doing this, but nothing..yet

    what is wrong with the following..

    Qt Code:
    1. // redirect table's painting on a pixmap
    2. QPixmap pixmap(totalWidth, totalHeight);
    3. QPainter::setRedirected(tableWidget->horizontalHeader()->viewport(), &pixmap);
    4. QPaintEvent event(QRect(0, 0, totalWidth, totalHeight));
    5. QApplication::sendEvent(tableWidget->horizontalHeader()->viewport(), &event);
    6. QPainter::restoreRedirected(tableWidget->horizontalHeader()->viewport());
    7.  
    8. QPixmap pixmap1(totalWidth, totalHeight);
    9. QPainter::setRedirected(tableWidget->viewport(), &pixmap1);
    10. QPaintEvent event1(QRect(0, 1, totalWidth, totalHeight));
    11. QApplication::sendEvent(tableWidget->viewport(), &event1);
    12. QPainter::restoreRedirected(tableWidget->viewport());
    13.  
    14. // print scaled pixmap
    15. QPainter painter(&printer);
    16. painter.scale(5,5);
    17. painter.drawPixmap(printer.pageRect().topLeft(), pixmap, pixmap.rect());
    18. painter.drawPixmap(printer.pageRect().topRight(), pixmap1, pixmap1.rect());
    To copy to clipboard, switch view to plain text mode 

    Thanks for your patience,

    Roby

  17. #17
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Printing QTableWidget

    Perhaps it would be easier to convert contents of the table to HTML and use QTextDocument::print()?
    J-P Nurmi

  18. The following user says thank you to jpn for this useful post:

    rmagro (21st June 2007)

  19. #18
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing QTableWidget

    Please provide some examples,

    Thank you

    Roberto

  20. #19
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Printing QTableWidget

    What does the table contain? Plain text? Images? Could you provide a screenshot?
    J-P Nurmi

  21. #20
    Join Date
    Jun 2007
    Location
    italy
    Posts
    126
    Thanks
    15
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Printing QTableWidget

    Here it is..

    Then, the following to show you how I fill in the table:
    Qt Code:
    1. tableWidget->item(row, 1)->setText(tr("Verifica corretta"));
    To copy to clipboard, switch view to plain text mode 

    many thanks..
    Roby
    Attached Files Attached Files

Similar Threads

  1. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  2. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  3. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.