Skip to content

table menu item to make screenshot of selected rows #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* @licence end@
*/

#include "qabstractitemmodel.h"
#include "qdebug.h"
#include <algorithm>
#include <QMimeData>
#include <QTreeView>
Expand Down Expand Up @@ -7005,6 +7007,38 @@ void MainWindow::on_tableView_customContextMenuRequested(QPoint pos)

menu.addSeparator();

action = new QAction("Copy Selection as image to Clipboard", this);
connect(action, &QAction::triggered, this, [this](){
// save and clear selection for clean screenshot
auto selectionIndexes = ui->tableView->selectionModel()->selection().indexes();

auto headerRect = ui->tableView->horizontalHeader()->rect();

ui->tableView->selectionModel()->clearSelection();

QRect res;
for (qsizetype i = 0; i < selectionIndexes.size(); ++i)
{
res |= ui->tableView->visualRect(selectionIndexes[i]);
}
// take into account height of the table header
res.translate(0, headerRect.height());

auto tableViewRect = ui->tableView->contentsRect();
auto pixmap = ui->tableView->grab(res & tableViewRect);

QApplication::clipboard()->setPixmap(pixmap);

// restore selection
for (const auto& index : selectionIndexes)
{
ui->tableView->selectionModel()->select(index, QItemSelectionModel::Select);
}
});
menu.addAction(action);

menu.addSeparator();

action = new QAction("&Export...", this);
if(qfile.sizeFilter() <= 0)
{
Expand Down
Loading