@@ -28,6 +28,28 @@ PlotDock::PlotDock(QWidget* parent)
2828 // connect slots that takes care that when an axis is selected, only that direction can be dragged and zoomed:
2929 connect (ui->plotWidget , SIGNAL (mousePress (QMouseEvent*)), this , SLOT (mousePress ()));
3030 connect (ui->plotWidget , SIGNAL (mouseWheel (QWheelEvent*)), this , SLOT (mouseWheel ()));
31+
32+ QShortcut* shortcutCopy = new QShortcut (QKeySequence::Copy, ui->plotWidget , nullptr , nullptr , Qt::WidgetShortcut);
33+ connect (shortcutCopy, SIGNAL (activated ()), this , SLOT (copy ()));
34+
35+ ui->plotWidget ->setContextMenuPolicy (Qt::CustomContextMenu);
36+
37+ // Set up context menu
38+ m_contextMenu = new QMenu (this );
39+ QAction* copyAction = new QAction (QIcon (" :/icons/copy" ), tr (" Copy" ), m_contextMenu);
40+ copyAction->setShortcut (shortcutCopy->key ());
41+ m_contextMenu->addAction (copyAction);
42+
43+ connect (copyAction, &QAction::triggered, [&]() {
44+ copy ();
45+ });
46+
47+ connect (ui->plotWidget , &QTableView::customContextMenuRequested,
48+ [=](const QPoint& pos) {
49+ // Show menu
50+ m_contextMenu->popup (ui->plotWidget ->mapToGlobal (pos));
51+ });
52+
3153}
3254
3355PlotDock::~PlotDock ()
@@ -612,3 +634,8 @@ void PlotDock::mouseWheel()
612634 else
613635 ui->plotWidget ->axisRect ()->setRangeZoom (Qt::Horizontal | Qt::Vertical);
614636}
637+
638+ void PlotDock::copy ()
639+ {
640+ QApplication::clipboard ()->setPixmap (ui->plotWidget ->toPixmap ());
641+ }
0 commit comments