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 allow user to configure keyboard shortcuts?
Forum Updated to NodeBB v4.3 + New Features

How to allow user to configure keyboard shortcuts?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 613 Views
  • 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.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by
    #1

    I'm developing an app with a lot of commands and would like to provide the user with a mechanism to customize the keyboard shortcuts.

    I'm having a hard time coming up with any solution that I would call elegant, since all my attempts so far require me to create a new class for each individual action I want to make available (Ie, I'm using ActionInfo to provide info about an action a user can configure, and subclassing ActionRunnable for each different action the user can take):

    class ActionInfo : QObject
    {
        Q_OBJECT
    
        QString _id;
        QString _name;
        ActionRunnable* _runnable;
        QPointer<QAction> _action;
    ...
    }
    

    I might be able to replace the _runnable with data I could use to indicate a slot, but I don't know the datatype I should use for this.

    Does Qt provide some sort of mechanism to make user configurable shortcuts easier? Any examples of this would be a big help.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by dheerendra
      #2

      Just a question. How do you provide mechanism for the user to define the keyboard shorts cuts ? Is it through some configuration file or user enters it ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      K 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Just a question. How do you provide mechanism for the user to define the keyboard shorts cuts ? Is it through some configuration file or user enters it ?

        K Offline
        K Offline
        kitfox
        wrote on last edited by kitfox
        #3

        @dheerendra I haven't written it yet, but I was thinking that the user could open a dialog box that shows a spreadsheet with two columns - names or ids of commands on the left and shortcuts on the right. I'd also consider using an XML file that maps command id names to keyboard shortcuts.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          You can use QKeyShort cut and make it happen. It could be some thing like follows.

          void MyWidgetShortCuts::on_pushButton_clicked()
          {
              QString text = this->ui->lineEdit->text();
              QShortcut *shortKey = new QShortcut(QKeySequence(text),this);
              connect(shortKey,SIGNAL(activated()),this,SLOT(callMe()));
          }
          

          text is keyboard short cut. You can define your own slot.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          1

          • Login

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