QTableView: how to take screenshot (grab widget) of complete content
-
Hello,
is it possible, to take a screenshot of the complete widget that is contained in a QTableView?
Think QScrollArea->widget()->grab().Background: I want to create a kind of overview scrollbar like SublimeText does.
I want to display a miniature version of the complete contents of the QTableView at the side of the TableView to be able to- get an overview
- use it to navigate (scroll) in the tableview
Thus it is important for me, to get a representation of all the content in the QTableView and not just the parts that are visible through the viewport.
Best regards,
Markus -
@ChrisW67
Let's just change a widget, like Qtablewidget, I add data to it more than a vertical screen, (maybe need 2 vertical screen). the widget will show scrollbar when it cannot show all.
Now i snap the content, how to see the full content in one picture? do i need scroll and take two picture, and finally combine to one picture? is there a combination algorithm inside Qt? if not , should we use opencv or halcon? -
Hi
Scrolling and combine to one picture could work but will be messy to get to align up.You could place the table in a scroll area so we can freely resize it
and then you can ask it to render to a pixmap like this
void MainWindow::on_pushButton_pressed() { // for readability auto table = ui->tableWidget; auto vheader = ui->tableWidget->verticalHeader(); auto hheader = ui->tableWidget->horizontalHeader(); // ask it to resize to size of all its text vheader->setSectionResizeMode( QHeaderView::ResizeToContents ); hheader->setSectionResizeMode( QHeaderView::ResizeToContents ); // tell it we never want scrollbars so they are not shown disabled vheader->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); hheader->setVerticalScrollBarPolicy(Qt::ScrollBarPolicy::ScrollBarAlwaysOff); // loop all rows and cols and grap sizes int iWidth = 0; int iHeight = 0; for (int i = 0; i < table->columnCount(); i++) { iWidth += hheader->sectionSize(i); } iWidth += vheader->width(); for (int i = 0; i < ui->tableWidget->rowCount(); i++) { iHeight += vheader->sectionSize(i); } iHeight += hheader->height(); QSize oldSize = table->size(); // now resize it to the size we just summed up table->resize(iWidth, iHeight); // ask it to renader to a pixmap QPixmap pixmap(ui->tableWidget->size()); table->render(&pixmap); pixmap.save("e:/test.png"); // restore org size table->resize(oldSize); }
and you get a pixmap with it all.