本文讲解Qt自定义QLineEdit控件添加鼠标单击事件。
QLineEdit控件默认没有单击事件,但是项目开发中有时需要单击事件,比如单击QLineEdit控件弹出软键盘。具体实现过程如下:
创建项目,在项目中添加一个类,命名为MyLineEdit
输入继承QLineEdit
#ifndef MYLINEEDIT_H
#define MYLINEEDIT_H#include <QObject>
#include <QLineEdit>
#include <QMessageBox>
class MyLineEdit : public QLineEdit
{Q_OBJECT//引入Q_OBJECT宏(预留)
public:MyLineEdit(QWidget *parent = 0);
protected:void mousePressEvent(QMouseEvent *event);
publi