Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use cut/copy/paste QKeySequence actions?
Forum Updated to NodeBB v4.3 + New Features

How to use cut/copy/paste QKeySequence actions?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 583 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexey Serebryakov
    wrote on last edited by Alexey Serebryakov
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You might want to rather filter on QShortcutEvent.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You might want to rather filter on QShortcutEvent.

        A Offline
        A Offline
        Alexey Serebryakov
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Indeed, it's usually associated with a QAction however your code uses eventFilter.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Indeed, it's usually associated with a QAction however your code uses eventFilter.

            A Offline
            A Offline
            Alexey Serebryakov
            wrote on last edited by
            #5

            @SGaist ok, please could you suggest me great solution?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Use actions and connect them to the cut, copy, paste slots.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved