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. [SOLVED]How to use shortcuts for QActions
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to use shortcuts for QActions

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.7k Views 1 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
    adnan
    wrote on last edited by
    #1

    I tried this, but it didn't work
    @deleteAction = new QAction(tr("Delete "),ui->tableWidget);
    connect(deleteAction, SIGNAL(triggered()),this,SLOT(on_actionDelete_triggered()));
    deleteAction->setShortcut(Qt::Key_Delete);
    deleteAction->setShortcutContext(Qt::WidgetShortcut);@

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _rmn
      wrote on last edited by
      #2

      You've a bit mistaken with enums
      "function proptotype":http://qt-project.org/doc/qt-4.8/qaction.html#shortcut-prop is:
      @
      void QAction::setShortcut(const QKeySequence &shortcut)
      @

      one of "QKeySeqence ctors":http://qt-project.org/doc/qt-4.8/qkeysequence.html#QKeySequence-6 :
      @
      QKeySequence::QKeySequence (StandardKey key)
      @

      where StandartKey: http://qt-project.org/doc/qt-4.8/qkeysequence.html#StandardKey-enum

      so you should use:
      @
      deleteAction->setShortcut(QKeySequence::Delete);
      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        adnan
        wrote on last edited by
        #3

        I tried this, but still it doesn't work:
        @deleteAction->setShortcut(QKeySequence::Delete);
        deleteAction->setShortcutContext(Qt::WidgetShortcut);@

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

          try this:

          @deleteAction->setShortcut(QKeySequence(Qt::Key_Delete))@

          1 Reply Last reply
          0
          • _ Offline
            _ Offline
            _rmn
            wrote on last edited by
            #5

            <deleted>

            1 Reply Last reply
            0
            • _ Offline
              _ Offline
              _rmn
              wrote on last edited by
              #6

              oh, try this:
              @
              ui->tableWidget->addAction(deleteAction);
              @

              1 Reply Last reply
              0
              • A Offline
                A Offline
                adnan
                wrote on last edited by
                #7

                Thanks a lot. It did the job

                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