QT按键增加按键音代码功能,代码如下:
void QKeyPushButton::mouseReleaseEvent(QMouseEvent *event)
{
QPushButton::mouseReleaseEvent(event);
mplay->execute(program,arguments); //此处调用"aplay click.wav"播放按键音文件
}
但是这样会导致一个现象,即在按键过快按下的时候,按键音延迟响应,给人一种“卡”的感觉,在此采用了单例模式的设计方法解决了该问题。关键代码如下:
class QKeythread : public QObject//单例类定义
{
Q_OBJECT
public:
static QKeythread* GetInstance();
public slots:
void play_key_sound(void);
void play_sound_slot(void);
private:
QKeythread();
static QKeythread *m_keyDeal;
QProcess *mplay;
{
Q_OBJECT
public:
static QKeythread* GetInstance();
public slots:
void play_key_sound(void);
void play_sound_slot(void);
private:
QKeythread();
static QKeythread *m_keyDeal;
QProcess *mplay;