zoukankan      html  css  js  c++  java
  • QT 按钮类继承处理带定时器

    01.class KeyButton : public QPushButton 
    02.{ 
    03.    Q_OBJECT 
    04.public: 
    05.    explicit KeyButton(QWidget *parent = 0) : QPushButton(parent), 
    06.        pauseMsecs(400), intervalMsecs(30) 
    07.    { 
    08.        tm = new QTimer(this); 
    09.        connect(tm, SIGNAL(timeout()), this, SLOT(on_pressed_last())); 
    10.        connect(this, SIGNAL(pressed()), this, SLOT(on_pressed())); 
    11.        connect(this, SIGNAL(released()), this, SLOT(on_released())); 
    12.        connect(this, SIGNAL(clicked()), this, SLOT(on_clicked())); 
    13.    } 
    14. 
    15.private: 
    16.    QTimer *tm; 
    17.    long pauseMsecs; 
    18.    long intervalMsecs; 
    19. 
    20.signals: 
    21.    void keyPressed(const QString &msg); 
    22.    void keyReleased(const QString &msg); 
    23.    void keyClicked(const QString &msg); 
    24. 
    25.public slots: 
    26.    void on_pressed() { emit this->keyPressed(this->text()); 
    27.                        tm->start(pauseMsecs); } 
    28.    void on_pressed_last() { emit this->keyPressed(this->text()); 
    29.                             tm->setInterval(intervalMsecs); } 
    30.    void on_released() { tm->stop(); emit this->keyReleased(this->text()); } 
    31.    void on_clicked() { emit this->keyClicked(this->text()); } 
    32.};

  • 相关阅读:
    day10 作业
    文件操作
    字符编码
    元组、字典、集合内置方法, 深浅拷贝
    day07作业
    一周总结
    mysql操作进阶
    mysql操作篇续
    mysql-操作篇
    mysql的安装
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/4384367.html
Copyright © 2011-2022 走看看