Qtembedded keyboard input method (example)

Source: Internet
Author: User

All posts on this site are reserved by this site and the original author. This article can only be reproduced if the copyright information, original article links, and original article authors are retained. Do not delete or modify the original article content for reprinting, it is not intended for commercial purposes. Thank you for your cooperation. Original article: qtembedded keyboard input method (example)

(This document is based on qte4.5 and is applicable to other versions)

Recently, I have seen many discussions about the qtembedded keypad. The most important questions are as follows:
1. How can I write a soft keyboard that does not compete with the focus of the program window?
2. How to send the keyboard key value to the focus widget
3. Other questions about the Chinese Input Method

 

First of all, it must be clear that the soft keyboard is actually a form of input method, so when designing and implementing the soft keyboard, we should first look for whether the system provides the input method API. Some people still have questions: "Why do I have to use the API of the input method? I can use the ordinary QT API to implement similar East-West Asia !" But this is not the case. Maybe you can write a soft keyboard window in your program that looks like an input method, but you must know that normal QTE APIs cannot span processes, if your system contains multiple programs, you must stop eating! On the contrary, the good news is that the QTE Input Method API can ensure that your input method can be used in various QTE programs. Pai_^ y

Due to the fact that the qtembedded document is not systematic enough, many may end up trying to find a needle in the ocean and use other odd methods to implement the functions required by the soft keyboard. This article aims to provide an introduction to the input method framework, and introduce the implementation of the soft keyboard, so that you can avoid detours.

The following describes the most important basis and framework of the input method. It uses a simple soft keyboard as the blueprint, and a general keyboard input method (such as a Chinese Input Method like scim) will be introduced later) how to implement it in qtembedded.

The QTE Input Method Framework has not changed much from the earlier qte2 to the current qte4. An input method must provide an instance of the qwsinputmethod class. Therefore, a derived class of qwsinputmethod must be implemented in the input method, in this derived class, the keyboard widget is displayed and operated, and the communication with the input method framework is completed. After the qwsserver process calls qwsserver: setcurrentinputmethod (qwsinputmethod *) to activate the input method,
The Input Method Framework sends application information to the qwsinputmethod class, which is processed by the virtual function of qwsinputmethod. So the core part is how to implement a derived class of qwsinputmethod, and how to make your keyboard window and the input window of the program coexist with qwsinputmethod.

The following QTE document mentions how to solve the first problem raised at the beginning of this article: http://doc.qt.nokia.com/4.5/qt-embedded-charinput.html. Its core is that the QT: tool attribute needs to be set for the keyboard widget to ensure that it does not compete for focus with the focus form.

For the second question, you can find most of the answers in the document of the qwsinputmethod class. The sendpreeditstring method provided by qwsinputmethod is used to send the pre-processed text to the focus form. Generally, the editor displays the text as underlined or dotted, indicating that it is a semi-finished product during editing; then, the qwsinputmethod: sendcommitstring function sends the final user confirmation text to the edit box.

After solving these two problems, we can write a simple soft keyboard input method, so I provide a small soft keyboard example to demonstrate how to solve the above two problems. This example is very simple. It contains the main. cpp and mainwin. * server processes representing QTE, while imframe. * is the derived class of qwsinputmethod, and inputwidget. * is the soft keyboard form. The qsignalmapper class introduced in the previous blog is also used in the program,
If you are not familiar with this type of content, read this post to scan for literacy. Others that do not understand can leave a message on the blog or BBS.

Imframe.tar

The qwsinputmethod derived class should also implement the updatehandler virtual function, which serves as a bridge between the input method framework and the input method, and sends some status information to the input method, for example, the updatehandler function will be called when the focus is left or the edit box is entered. Here, you can add your input method to display or hide the input method widget at the right time. I have also rewritten this function in my example, but I didn't write any practical functions. I just added the Input Method for clearing. (Don't want to write code)

This example is developed based on qtembedded 4.5 and can be run in qvfb. The program architecture of input methods in other versions is similar, but the qwsinputmethod APIs may differ greatly. The document of each version prevails.

The above is the simplest soft keyboard input method. If you want to implement a keyboard input method like scim or a touch screen hand-written input method, it is much more complicated, the most important thing is how to receive user input before the focus form. here we need to use the qwsinputmethod: Filter virtual function. I am not going to introduce the input method too much here. If you still cannot understand the document, you need to find a good example. We recommend a qtopia input method. You can find the pkim Input Method in the src/3 rdparty/plugins/inputmethod/pkim directory of the qtopia or qtextended source code package,
This input method has excellent functions, including both keyboard input and handwriting input. Therefore, it is an excellent development blueprint.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.