How to use cut/copy/paste QKeySequence actions?
-
Hi guys,
i have implementation of copy/cut/paste items in my QTreeView-derived widget. Now I would like to provide these actions with StandardKeys.
I've created actions with QKeySequence::Cut, QKeySequence::Copy, QKeySequence::Paste and added to my context menu. Great!. But shortcuts does not work.
Then I've re-implemented MyTreeView::eventFilter like this:bool MyTreeView::eventFilter(QObject *, QEvent *event) { ... // something else case QEvent::KeyPress: { if (auto *keyEvent = dynamic_cast<QKeyEvent*>(event)) { if (keyEvent->matches(QKeySequence::Cut)) { cut(); } else if (keyEvent->matches(QKeySequence::Copy) // and so on } }
Ok, it work. But what about the issue with passed QKeySequence when I've created actions?
Thanks a lot.
-
Hi,
You might want to rather filter on QShortcutEvent.
-
Hi,
You might want to rather filter on QShortcutEvent.
@SGaist I see but look at https://doc.qt.io/qt-5/qshortcutevent.html#details.
Also I thought that was automatically when I've created action.
-
Indeed, it's usually associated with a QAction however your code uses eventFilter.
-
@SGaist ok, please could you suggest me great solution?
-
Use actions and connect them to the cut, copy, paste slots.