Qt数字软键盘

7750阅读 0评论2014-01-15 luozhiyong131
分类:嵌入式

使用QSignalMapper类实现一个数字软键盘

基本使用如下:

点击(此处)折叠或打开

  1. QSignalMapper *m = QSignalMapper(this);
  2. QPushButton *b;
  3. b=new QPushButton("1");
  4. connect(b, SIGNAL(clicked()),m, SLOT(map()));
  5. m->setMapping(b, 1);
  6. ...
  7. connect(m, SIGNAL(mapped(int)), this, SLOT(keyPressed(int)));
示例程序:

点击(此处)折叠或打开

  1. SoftKeyboardDlg::SoftKeyboardDlg(QWidget *parent) :
  2.     QDialog(parent),
  3.     ui(new Ui::SoftKeyboardDlg)
  4. {
  5.     ui->setupUi(this);

  6.     SetWindowBackColour(this);
  7.     m = new QSignalMapper(this);

  8.     connect(ui->buttonZero,SIGNAL(clicked()),m,SLOT(map()));
  9.     connect(ui->buttonOne,SIGNAL(clicked()),m,SLOT(map()));
  10.     connect(ui->buttonTwo,SIGNAL(clicked()),m,SLOT(map()));
  11.     connect(ui->buttonThree,SIGNAL(clicked()),m,SLOT(map()));
  12.     connect(ui->buttonFour,SIGNAL(clicked()),m,SLOT(map()));
  13.     connect(ui->buttonFive,SIGNAL(clicked()),m,SLOT(map()));
  14.     connect(ui->buttonSix,SIGNAL(clicked()),m,SLOT(map()));
  15.     connect(ui->buttonEight,SIGNAL(clicked()),m,SLOT(map()));
  16.     connect(ui->buttonSeven,SIGNAL(clicked()),m,SLOT(map()));
  17.     connect(ui->buttonNine,SIGNAL(clicked()),m,SLOT(map()));
  18.     connect(ui->pushButtonX,SIGNAL(clicked()),m,SLOT(map()));
  19.     connect(ui->pushButtonDel,SIGNAL(clicked()),m,SLOT(map()));

  20.     m->setMapping(ui->buttonZero,0);
  21.     m->setMapping(ui->buttonOne,1);
  22.     m->setMapping(ui->buttonTwo,2);
  23.     m->setMapping(ui->buttonThree,3);
  24.     m->setMapping(ui->buttonFour,4);
  25.     m->setMapping(ui->buttonFive,5);
  26.     m->setMapping(ui->buttonSix,6);
  27.     m->setMapping(ui->buttonSeven,7);
  28.     m->setMapping(ui->buttonEight,8);
  29.     m->setMapping(ui->buttonNine,9);
  30.     m->setMapping(ui->pushButtonX,10);
  31.     m->setMapping(ui->pushButtonDel,-1);

  32.     connect(m,SIGNAL(mapped(int)),this,SLOT(keyPress(int)));
  33.     ui->buttonOne->setFocus();
  34.     setStyleSheet(BTN_FOCUS_BACK_COLOR);
  35. }

  36. SoftKeyboardDlg::~SoftKeyboardDlg()
  37. {
  38.     delete ui;
  39. }

  40. void SoftKeyboardDlg::keyPress(int i)
  41. {
  42.     emit keyNum(i);
  43. }



上一篇:STM32 官方固件库简介
下一篇:STM32 系统架构