zoukankan      html  css  js  c++  java
  • 17.QT键盘

    • mainwindow.h
       1 #ifndef MAINWINDOW_H
       2 #define MAINWINDOW_H
       3 
       4 #include <QMainWindow>
       5 #include <QKeyEvent>
       6 
       7 namespace Ui {
       8 class MainWindow;
       9 }
      10 
      11 class MainWindow : public QMainWindow
      12 {
      13     Q_OBJECT
      14 
      15 public:
      16     explicit MainWindow(QWidget *parent = 0);
      17     ~MainWindow();
      18 
      19     void keyPressEvent(QKeyEvent *event);
      20 private:
      21     Ui::MainWindow *ui;
      22 };
      23 
      24 #endif // MAINWINDOW_H
    • mainwindow.cpp
       1 #include "mainwindow.h"
       2 #include "ui_mainwindow.h"
       3 
       4 MainWindow::MainWindow(QWidget *parent) :
       5     QMainWindow(parent),
       6     ui(new Ui::MainWindow)
       7 {
       8     ui->setupUi(this);
       9 }
      10 
      11 MainWindow::~MainWindow()
      12 {
      13     delete ui;
      14 }
      15 
      16 void MainWindow::keyPressEvent(QKeyEvent *event)
      17 {
      18     int x = ui->pushButton->x();
      19     int y = ui->pushButton->y();
      20     switch (event->key()) {
      21     case Qt::Key_A:
      22         ui->pushButton->move(x-10,y);
      23         break;
      24     case Qt::Key_D:
      25         ui->pushButton->move(x+10,y); 
      26         break;
      27     case Qt::Key_W:
      28         ui->pushButton->move(x,y-10);
      29         break;
      30     case Qt::Key_S:
      31         ui->pushButton->move(x,y+10);
      32         break;
      33     default:
      34         break;
      35     }
      36 }
  • 相关阅读:
    poj 3159 Candies
    强连通分量——Tarjan算法
    nyoj 次方求模
    nyoj 快速查找素数
    nyoj 光棍节的快乐
    拓扑排序
    快速幂取模
    nyoj 最大素因子
    素数打表
    nyoj 数的长度
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8747545.html
Copyright © 2011-2022 走看看