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.};

  • 相关阅读:
    this指向问题
    b继承a的函数
    如何解决跨域问题
    事件冒泡和阻止事件冒泡
    Spring5(二)——IOC
    MySQL基础(四)——
    MySQL基础(二)——常用命令
    MySQL基础(一)——入门
    Linux(二)——常用命令
    Linux(一)——简介
  • 原文地址:https://www.cnblogs.com/luxiaolai/p/4384367.html
Copyright © 2011-2022 走看看