The problem that the input method syszuxpinyin based on embedded Qt automatically pops up the software disk

The ported syszuxpinyin input method can normally detect the focus of the control and automatically pop up the soft keyboard.
When using the default QLineEdit control, there are some small problems:
Problem 1: QLineEditt will automatically appear the focus by default, resulting in a Entering the interface will pop up the soft keyboard
, but we need to click the control to pop up the soft keyboard.
Solution: set QLineEditthe property to setFocusPolicy(Qt::StrongFocus)or setFocusPolicy(Qt::ClickFocus);
This is a description in the help document:

The policy is Qt::TabFocus if the widget accepts keyboard focus by
tabbing,Qt::ClickFocus if the widget accepts focus by clicking,
Qt::StrongFocus if it accepts both, and Qt::NoFocus (the default) if
it does not accept focus at all

Question 2: By default, you can enter again without clicking other controls after inputting. To put it simply, it can pop up the first time, but not the second time. The reason is that the control cannot regain focus, only when it loses the
focus The focus can only be regained when it is in focus, so you must first click other controls to make it lose focus, and then click it to
regain focus. You will know after testing on the board.
Solution: subclass QLineEdit.h
file

 #ifndef _QLINEEDITIM_H
#define _QLINEEDITIM_H
#include <QLineEdit>
#include <QMouseEvent>
class QLineEditIM : public QLineEdit
{
    
    
	Q_OBJECT
public:
	explicit QLineEditIM(QWidget *parent = 0);
protected:
	virtual void mousePressEvent(QMouseEvent *event);
signals:
	void clicked();
	public slots:
	void showInputMethod();
};
 
#endif //_QLINEEDITIM_H

.cpp file

#include "syszuxim.h"
#include "syszuxpinyin.h"
#include "qlineeditIM.h"

QLineEditIM::QLineEditIM(QWidget *parent):
QLineEdit(parent)
{
    
    
	QWSInputMethod *im = new SyszuxIM;
	QWSServer::setCurrentInputMethod(im);
	connect(this, SIGNAL(clicked()), this, SLOT(showInputMethod()));
}
 

void QLineEditIM::mousePressEvent(QMouseEvent *event)
{
    
    
	if (event->button() == Qt::LeftButton)
	{
    
    
		emit clicked();
	}
	QLineEdit::mousePressEvent(event);
}
 
/*
* name : void showInputMethod()
* Type : QEvent
* Func : show inputthmod
* in : Null
* out : Null
*/
void QLineEditIM::showInputMethod()
{
    
    
	clearFocus();
	setFocus();
}

Guess you like

Origin blog.csdn.net/qq_40170041/article/details/131701220