Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / C++

Short Key Reminder Display

Rate me:
Please Sign up or sign in to vote.
4.17/5 (9 votes)
29 Jan 2011CPOL2 min read 64K   321   10   8
This is an original idea - a short key reminder display with Qt

Introduction

Recently I begin a new job, and have to develop a software under linux with Qt.

They made some software with a lot of shortkey with only a poor dialog box in the help menu to know them.

So I'm impressed by the Qt Framework. It is so easy to develop with it and I found an interesting way to show Short key helper with Qt.

Have a look at an interesting article on Qt.

Background

My idea is when the user presses the CTRL key, then a message appears on the display to show all short keys available with ctrl.

It's possible in Qt with the installEventFilter method.

I made a simple project with Qt Creator, it's really easy to make it by the wizard, and the GUI designer.

I place a pushButton in the center, and set a short cut ctrl-D on this button.

ShortKeyReminderDisplay/basic.png

Then the project in Qt Creator looks like that:

ShortKeyReminderDisplay/projet.png

When I run the program and go on the window, and press CTRL, a tooltip appears:

ShortKeyReminderDisplay/tooltipAppear.png

And after I press D, the action I develop for the application arrives.

Using the Code

My principal object is MainWindow.

C++
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
   this->installEventFilter(this);
   QObject::connect(ui->pushButton,SIGNAL(clicked()), this, SLOT(click_pick()));
}

The important thing here is to notice:

C++
this->installEventFilter(this);

This sets a handler event on the mainwindow (may be like a winproc in Windows technology).

C++
bool MainWindow::eventFilter (QObject* obj, QEvent* e)
  {     
       if (e->type () == QEvent::KeyPress)
      {
          QKeyEvent* k = (QKeyEvent*) e;

          if (k->key () == Qt::Key_Control)
          {
              QToolTip::showText(QPoint(0,0),QString
        ("Help reminder short keys : <br/>  ctrl-D : push Button"));
          }
      }
       else
       {
           if (e->type () == QEvent::KeyRelease)
           {
               QKeyEvent* k = (QKeyEvent*) e;
               if (k->key () == Qt::Key_Control)
               {
                   QToolTip::hideText();
               }
           }
           else
           {
               return QObject::eventFilter(obj, e);
           }
       }
      return false;
  }

The interest here is to notice the using of the QTooltip object to show the short key reminder. It's really practical because you can place the tooltip where you want on the screen, and make it disappear easily.

Points of Interest

I want to share with you this idea about a short key reminder display and the way to realize it. And I want to share with you also my opinion about Qt Framework, try it, it's amazing. I don't know how to realize it with Winform or in WPF, but I guess it's possible. So if you want to be friendly with new users of your application, use this idea to make short key reminder display to help them in the beginning. Sorry for my poor English, I'm French.

History

  • 29th January, 2011: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) http://www.cmb-soft.com/
France France
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Carlo Capelli22-Jul-13 21:02
Carlo Capelli22-Jul-13 21:02 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey26-Feb-12 21:11
professionalManoj Kumar Choubey26-Feb-12 21:11 
QuestionWhat IDE for developing in QT? Pin
Aoi Karasu 10-Feb-11 4:14
professional Aoi Karasu 10-Feb-11 4:14 
AnswerRe: What IDE for developing in QT? Pin
zebulon7501819-Feb-11 7:37
zebulon7501819-Feb-11 7:37 
GeneralMy vote of 1 Pin
Konstantin Mamutov31-Jan-11 10:36
professionalKonstantin Mamutov31-Jan-11 10:36 
GeneralRe: My vote of 1 Pin
xComaWhitex31-Jan-11 16:48
xComaWhitex31-Jan-11 16:48 
GeneralRe: My vote of 1 Pin
Konstantin Mamutov31-Jan-11 21:27
professionalKonstantin Mamutov31-Jan-11 21:27 
GeneralRe: My vote of 1 Pin
zebulon750181-Feb-11 9:27
zebulon750181-Feb-11 9:27 
GeneralRe: My vote of 1 Pin
Konstantin Mamutov1-Feb-11 10:01
professionalKonstantin Mamutov1-Feb-11 10:01 
I completely agree with you сoncerning the QT framework. Now I also work with this library, before many years worked with MFC and ATL.
That I can tell.... I in delight from QT!
Probably your article will be useful to someone. I didn't want you to offend, and have simply expressed the personal opinion.
GeneralRe: My vote of 1 Pin
idle6325-Dec-13 5:26
idle6325-Dec-13 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.