* In : QObject,QEvent
* Out : bool
*/
bool InputMethod::eventFilter(QObject *obj, QEvent *event)
{
if(event->type()==QEvent::MouseButtonPress)
{
showKeyBoard();
return true;
}
return QObject::eventFilter(obj,event);
}
/*
* Name : void showKeyBoard();
* Type : function
* Func : show keyBoard
* In : Null
* Out : Null
*/
void InputMethod::showKeyBoard()
{
keyboard->setWindowFlags(Qt::Tool|Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint);
keyboard->move(50,120);
keyboard->exec();
}
qlineeditwithim.h
[html] view plaincopyprint #ifndef QLINEEDITWITHIM_H
#define QLINEEDITWITHIM_H
#include
#include "inputmethod.h"
class QLineEditWithIM : public QLineEdit
{
public:
QLineEditWithIM();
private:
InputMethod *im;
};
#endif // QLINEEDITWITHIM_H
#ifndef QLINEEDITWITHIM_H
#define QLINEEDITWITHIM_H
#include
#include "inputmethod.h"
class QLineEditWithIM : public QLineEdit
{
public:
QLineEditWithIM();
private:
InputMethod *im;
};
#endif // QLINEEDITWITHIM_H
qlineeditwithim.cpp
[html] view plaincopyprint #include "qlineeditwithim.h"
QLineEditWithIM::QLineEditWithIM()
{
//#ifdef Q_WS_QWS
im = new InputMethod;
installEventFilter(im);
connect(im->keyboard,SIGNAL(setvalue(QString)),this,SLOT(setText(QString)));
//#endif
}
#include "qlineeditwithim.h"
QLineEditWithIM::QLineEditWithIM()
{
//#ifdef Q_WS_QWS
im = new InputMethod;
installEventFilter(im);
connect(im->keyboard,SIGNAL(setvalue(QString)),this,SLOT(setText(QString)));
//#endif
}
login.h
[html] view plaincopyprint #ifndef LOGIN_H
#define LOGIN_H
#include
#include "qlineeditwithim.h"
class QLabel;
class QLineEdit;
class QDialogButtonBox;
class QLogin : public QDialog
{
Q_OBJECT
public:
QLogin();
~QLogin();
public:
QLabel *managerLabel;
QLabel *passwdLabel;
QLineEditWithIM *managerEdit;
QLineEditWithIM *passwdEdit;
QPushButton *okButton;
QPushButton *cancelButton;
QDialogButtonBox *buttonBox;
signals:
void Authorize();
private slots:
void login();
void cancel();
};
#endif // LOGIN_H
#ifndef LOGIN_H
#define LOGIN_H
#include
#include "qlineeditwithim.h"
class QLabel;
class QLineEdit;
class QDialogButtonBox;
class QLogin : public QDialog
{
Q_OBJECT
public:
QLogin();
~QLogin();
public:
QLabel *managerLabel;
QLabel *passwdLabel;
QLineEditWithIM *managerEdit;
QLineEditWithIM *passwdEdit;
QPushButton *okButton;
QPushButton *cancelButton;
QDialogButtonBox *buttonBox;
signals:
void Authorize();
private slots:
void login();
void cancel();
};
#endif // LOGIN_H
login.cpp
[html] view plaincopyprint #include
#include "login.h"
QLogin::QLogin()
{
managerLabel = new QLabel(tr("&Manager:"));
managerEdit = new QLineEditWithIM();
managerLabel->setBuddy(managerEdit);
passwdLabel = new QLabel(tr("&Passwd:"));
passwdEdit = new QLineEditWithIM;
passwdEdit->setEchoMode(QLineEdit::Password);
passwdLabel->setBuddy(passwdEdit);
okButton = new QPushButton(tr("&Login"));
cancelButton = new QPushButton("&Cancel");
okButton->setDefault(true);
buttonBox = new QDialogButtonBox;
buttonBox->addButton(okB