PDA

View Full Version : Grabbing QTableWidget's viewport



u-ra
27th November 2009, 14:16
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:



int w = table->model()->columnCount() * table->columnWidth(0);
int h = table->model()->rowCount() * table->rowHeight(0);

QPixmap pixmap(w, h);

QPainter::setRedirected(table->viewport(), &pixmap);
QPaintEvent event(QRect(0, 0, w, h));
QApplication::sendEvent(table->viewport(), &event);
QPainter::restoreRedirected(table->viewport());

pixmap.save("viewport.png", "png");


Any ideas? Thanks in advance.

wysota
27th November 2009, 16:26
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.

u-ra
30th November 2009, 10:29
I see. So what are my options? Use the delegate to paint each cell? I would probably need to draw the grid manually, right?

wysota
30th November 2009, 11:07
You have to do everything manually, I'm afraid.