The   The 

Introduction

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

And they made some software with a lot of shortkey with only a poor dialog box in the help menu to kno them.

So I'm impress by the Qt Framework , it's so easy to develop with it and I found an interresting way to show Short key helper with Qt. 

Have a look to an interesting article on Qt

Background  

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

It's possible in Qt with the installEventFilter  method 

I made a simple projet 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. 

basic.png

Then the project in Qt Creator look like that:

projet.png

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

tooltipAppear.png

And if after I press D , so the action I develop for the application arrive.

Using the code 

My principal objet is MainWindow.  


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 here is to notice :
this->installEventFilter(this);

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

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 objet to show the short key reminder. It's really pratical because you can place the tooltip where you want on the screen, and make it dissappear 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 friendly with new users of your application , use this idea to make short key reminder display to help them in the begining. Sorry for my poor english , I'm. french
推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架