qt怎样实现在将鼠标点进lineEdit、textEdit时,即光标出现时调用某个函数。我想在光标出现在lineEdit中时调用一个键盘,实现类似手机发短信时效果(点下后出现键盘)?
Qt 光标
------解决方案--------------------
#include <QtCore>
#include <QtGui>
class MyLineEdit : public QLineEdit {
public:
MyLineEdit(QWidget *parent = NULL) : QLineEdit(parent) {}
protected:
virtual void focusInEvent(QFocusEvent *event) {
qDebug()<<"MyLineEdit";
QLineEdit::focusInEvent(event);
}
};
class MyTextEdit : public QTextEdit {
public:
MyTextEdit(QWidget *parent = NULL) : QTextEdit(parent) {}
protected:
virtual void focusInEvent(QFocusEvent *event) {
qDebug()<<"MyTextEdit";
QTextEdit::focusInEvent(event);
}
};
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QDialog *dlg = new QDialog();
QLayout *layout = new QVBoxLayout(dlg);
QLineEdit *lineEdit = new MyLineEdit(dlg);
layout->addWidget(lineEdit);
QTextEdit *textEdit = new MyTextEdit(dlg);
layout->addWidget(textEdit);
dlg->setLayout(layout);
dlg->show();
return app.exec();
}