Results 1 to 20 of 22

Thread: Printing QTableWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 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

  2. #2
    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

  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 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

  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

    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

  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

    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

  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

    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

  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

    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?

  8. #8
    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

  9. #9
    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

  10. #10
    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

  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: 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.

  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: 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

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