Results 1 to 4 of 4

Thread: Grabbing QTableWidget's viewport

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Grabbing QTableWidget's viewport

    Hi,

    I'm trying to grab the entire viewport of a QTableWidget using redirection. However, the result is still clipped to QTableWidget's rect. Here's the code:

    Qt Code:
    1. int w = table->model()->columnCount() * table->columnWidth(0);
    2. int h = table->model()->rowCount() * table->rowHeight(0);
    3.  
    4. QPixmap pixmap(w, h);
    5.  
    6. QPainter::setRedirected(table->viewport(), &pixmap);
    7. QPaintEvent event(QRect(0, 0, w, h));
    8. QApplication::sendEvent(table->viewport(), &event);
    9. QPainter::restoreRedirected(table->viewport());
    10.  
    11. pixmap.save("viewport.png", "png");
    To copy to clipboard, switch view to plain text mode 

    Any ideas? Thanks in advance.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grabbing QTableWidget's viewport

    The viewport is smaller than the view. The scrolled canvas is purely virtual. Thus you can't just render the viewport and have all the table on the pixmap because the viewport can only hold that many items that are currently displayed in the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Grabbing QTableWidget's viewport

    I see. So what are my options? Use the delegate to paint each cell? I would probably need to draw the grid manually, right?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Grabbing QTableWidget's viewport

    You have to do everything manually, I'm afraid.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 12th February 2008, 21:17

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.