A method and system for implementing an embedded QT virtual keyboard based on QWidget container

CN122924655APending Publication Date: 2026-10-16GUANGZHOU XINGYI ELECTRONICS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611323848.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-28
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0005]本发明的目的在于:针对目前存在的嵌入式平台现有技术中虚拟键盘只能通过QML调用,与QWidget应用集成困难、布局不灵活、依赖系统输入法的对应支持和定制化程度低的问题

Benefits of technology

在本申请的方案中:

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122924655A_ABST
    Figure CN122924655A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of computer human-computer interaction, in particular to an embedded QT virtual keyboard implementation method and system based on a QWidget container, which comprises the following steps: S101, establishing a communication bridge for realizing bidirectional transmission of instructions and data between a QML virtual keyboard and a QWidget application; S102, setting a focus response mechanism for controlling display and hiding of the QML virtual keyboard through the communication bridge according to a focus state of a QWidget input control; and S103, dynamically embedding the QML virtual keyboard into a QWidget application interface through a layout controller and positioning and displaying the QML virtual keyboard relative to an input control currently obtaining a focus. The application seamlessly integrates: the virtual keyboard is completely taken as a part of the QWidget system, can be managed like any ordinary control, and is perfectly fused with the application program based on the QWidget; the layout is flexible, the keyboard can be embedded into any parent container, and multiple layout strategies are supported.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer human-computer interaction technology, and more specifically, to an embedded QT virtual keyboard implementation method and system based on the QWidget container. Background Technology

[0002] With the widespread adoption of embedded devices, such as industrial control touchscreens, smart home central control systems, and in-vehicle infotainment systems, touchscreens have become the primary human-machine interface. On these devices, physical keyboards are often no longer suitable, and virtual keyboards (or soft keyboards) have become indispensable input components. Qt, as a cross-platform C++ graphical user interface application framework, has been widely used in the embedded field. Qt officially provides the QVirtualKeyboard module, but it is primarily designed for QML applications and Quick controls. Furthermore, while the Qt virtual keyboard's server-side implementation is done on the embedded platform, it lacks corresponding support for Wayland, elgfs, and linuxfb plugin platforms. For legacy projects or specific projects that heavily utilize traditional QWidget technology, the integration process is complex and lacks flexibility and customization.

[0003] Traditional QWidget applications cannot directly use the QT virtual keyboard, making it difficult to achieve a non-top-level keyboard effect embedded within a specific window. Layout management is inflexible: existing solutions typically treat the virtual keyboard as a global singleton, and its display and hiding affect the layout of the entire application. It is impossible to display the keyboard only in a child window or area containing a specific text input box. Customization is difficult: developers find it difficult to deeply customize the style and layout of the virtual keyboard (such as displaying only the numeric keypad) and embed it into complex user interface layouts according to product requirements. There are also relatively few input method types for open-source QT soft keyboards on the market.

[0004] Therefore, we have made improvements to this by proposing an embedded QT virtual keyboard implementation method and system based on the QWidget container. Summary of the Invention

[0005] The purpose of this invention is to address the problems in existing embedded platform technologies where virtual keyboards can only be invoked via QML, resulting in difficulties in integration with QWidget applications, inflexible layout, reliance on system input method support, and low customization.

[0006] To achieve the above-mentioned objectives, this invention provides an embedded QT virtual keyboard implementation method and system based on the QWidget container, in order to improve the aforementioned problems.

[0007] The application is as follows: An embedded QT virtual keyboard implementation method based on a QWidget container includes the following steps: S101. Establish a communication bridge to enable bidirectional transmission of commands and data between the QML virtual keyboard and the QWidget application; S102. Set a focus response mechanism to control the display and hiding of the QML virtual keyboard through the communication bridge according to the focus state of the QWidget input control; S103. Using a layout controller, the QML virtual keyboard is dynamically embedded into the QWidget application interface, and its position is displayed relative to the input control that currently has focus. S104. Using an event converter, the input operation of the QML virtual keyboard is converted into the input event of the QWidget input control.

[0008] As a preferred technical solution of this application, the communication bridge is a C++ class based on the Qt meta-object system, which completes the bidirectional transmission by exposing callable interfaces to the QML environment and providing a signal transmission mechanism to the QWidget environment.

[0009] As a preferred technical solution of this application, the focus response mechanism is implemented by installing a global event filter for the QWidget application.

[0010] As a preferred technical solution of this application, when the global event filter detects a focus acquisition event, it not only sends a keyboard display command to the QML environment through the communication bridge, but also records the type information of the input control that acquires focus. The type information includes, but is not limited to, text input box, password input box and numeric input box. When different types of input controls trigger the display of the QML virtual keyboard, they can pass parameters to the QML environment so that the QML virtual keyboard displays the corresponding key layout according to the type of input control.

[0011] As a preferred technical solution of this application, when the layout controller dynamically embeds the QML virtual keyboard into the QWidget application interface, it will adaptively adjust according to the screen resolution and screen orientation of the current device. When the screen orientation changes from landscape to portrait, the layout controller will recalculate the display position and size of the QML virtual keyboard relative to the input control that has gained focus, to ensure that the keyboard can be displayed in different screen orientations. For high-resolution screens, the size and spacing of the keyboard keys will be increased.

[0012] As a preferred technical solution of this application, the event converter has an input verification function when converting the input operation of the QML virtual keyboard into the input event of the QWidget input control. The event converter will verify the input content before converting the input event. If the input content does not meet the rule requirements of the input control, the event converter will prevent the transmission of the input event and can send error information to the QML virtual keyboard through the communication bridge, display prompt text on the keyboard, and prompt the user to re-enter the correct content.

[0013] As a preferred technical solution of this application, it also includes a history input record module for storing the user's historical input content on the QML virtual keyboard. The history input record module classifies and stores the historical input according to the input control type and input time. When the user gains focus on the same type of input control again and triggers the QML virtual keyboard display, the historical input list of that type of input control is obtained from the history input record module through the communication bridge and displayed on the QML virtual keyboard.

[0014] An embedded QT virtual keyboard system based on a QWidget container includes a keyboard UI building module for implementing step S101, generating a reusable keyboard widget; a focus listening module for implementing step S102, listening for and determining whether the keyboard needs to pop up; a layout management module for implementing step S103, responsible for the positioning, embedding, and display of the keyboard; and an event injection module for implementing step S104, converting virtual key operations into standard keyboard events.

[0015] As a preferred technical solution of this application, it also includes an input validation module: before the event injection module converts the virtual key operation into a standard keyboard event, the input content is validated. For different types of input controls, the input validation module checks the input characters one by one according to preset rules. If the input content does not conform to the rules, the input validation module will prevent the further transmission of the input event, and can display error prompts on the virtual keyboard through interaction with the keyboard UI construction module.

[0016] As a preferred technical solution of this application, the keyboard UI building module can load keyboard layout files of different languages ​​according to the user's selection settings and generate virtual keyboard widgets of the corresponding languages; when displaying the virtual keyboard, the layout management module will automatically adjust the character display and layout structure of the keyboard according to the selected language to adapt to the character characteristics and input habits of different languages.

[0017] Compared with the prior art, the beneficial effects of the present invention are as follows: In the scheme of this application: 1. To address the issues in existing embedded platform virtual keyboards that can only be invoked via QML, resulting in difficulties in integration with QWidget applications, inflexible layout, reliance on system input method support, and low customization, this application offers seamless integration: the virtual keyboard is fully integrated as part of the QWidget ecosystem, can be managed like any ordinary control, and perfectly blends with QWidget-based applications; the layout is flexible, the keyboard can be embedded in any parent container, supports multiple layout strategies, and can achieve non-modal, non-top-level embedded display.

[0018] 2. This application offers a better user experience; it is highly customizable, as the QT virtual keyboard is based on QML, and its appearance can be easily changed by modifying its style, and the numeric keypad and full keyboard can also be switched; it is highly versatile, as this method does not depend on a specific operating system or hardware platform, and can be used in any embedded environment that supports QT Widgets.

[0019] 3. This application enhances the input accuracy and stability of the system. The interaction between the input verification module and the keyboard UI construction module can promptly provide error information to the user, guide the user to input correct content, avoid invalid input and erroneous data, and improve the overall quality of the system. Attached Figure Description

[0020] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation

[0021] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0022] This invention provides a method for implementing an embedded QT virtual keyboard based on a QWidget container, comprising the following steps: S101. Establish a communication bridge to enable bidirectional transmission of commands and data between the QML virtual keyboard and the QWidget application; S102. Set up a focus response mechanism to control the display and hiding of the QML virtual keyboard through a communication bridge based on the focus state of the QWidget input control; S103. Using a layout controller, dynamically embed the QML virtual keyboard into the QWidget application interface and position it relative to the currently focused input control. S104. Using an event converter, the input operation of the QML virtual keyboard is converted into the input event of the QWidget input control.

[0023] This invention offers seamless integration: the virtual keyboard is fully integrated into the QWidget ecosystem, managed like any ordinary control, and perfectly blends with QWidget-based applications; flexible layout, the keyboard can be embedded in any parent container, supporting multiple layout strategies, enabling non-modal, non-top-level embedded display for a better user experience; high customizability, since the QT virtual keyboard is based on QML, its appearance can be easily changed by modifying its style, and the numeric keypad and full keyboard can be switched; and strong versatility, this method is not dependent on a specific operating system or hardware platform, and can be used in any embedded environment that supports QT Widgets.

[0024] To enable those skilled in the art to better understand the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings.

[0025] Example 1, please refer to Figure 1 An embedded QT virtual keyboard implementation method based on a QWidget container includes the following steps: S101. Establish a communication bridge to enable bidirectional transmission of commands and data between the QML virtual keyboard and the QWidget application; S102. Set up a focus response mechanism to control the display and hiding of the QML virtual keyboard through a communication bridge based on the focus state of the QWidget input control; S103. Using a layout controller, dynamically embed the QML virtual keyboard into the QWidget application interface and position it relative to the currently focused input control. S104. Using an event converter, the input operation of the QML virtual keyboard is converted into the input event of the QWidget input control.

[0026] By installing a global event filter on the QWidget application to implement a focus response mechanism, focus acquisition events can be captured comprehensively and accurately, ensuring timely response and control of the display and hiding of the QML virtual keyboard in various situations. The use of a global event filter simplifies code logic, avoids the tedious operation of setting focus listeners individually on each input control, and improves development efficiency and code maintainability.

[0027] The communication bridge is a C++ class based on the Qt meta-object system. It exposes callable interfaces to the QML environment and provides a signal emission mechanism to the QWidget environment to complete bidirectional transmission. It makes full use of the powerful functions of the Qt framework, ensuring the efficiency and stability of communication. The design of the C++ class makes the communication bridge have good extensibility and maintainability, and it is easy to add new functions and interfaces to adapt to the needs of different scenarios. The implementation method also improves code reusability and reduces development costs.

[0028] The focus response mechanism is implemented by installing a global event filter on the QWidget application. It can comprehensively and accurately capture focus acquisition events, ensuring timely response and control of the display and hiding of the QML virtual keyboard in various situations. The use of the global event filter simplifies the code logic, avoids the tedious operation of setting focus listeners individually on each input control, and improves development efficiency and code maintainability.

[0029] When the global event filter detects a focus acquisition event, it not only sends a keyboard display command to the QML environment through the communication bridge, but also records the type information of the input control that has acquired focus. The type information includes, but is not limited to, text input boxes, password input boxes, and numeric input boxes. When different types of input controls trigger the display of the QML virtual keyboard, they can pass parameters to the QML environment so that the QML virtual keyboard displays the corresponding key layout according to the type of input control. This further enhances the intelligence and personalization of the virtual keyboard. Different types of input controls have different input requirements. By displaying the corresponding key layout, users can input more conveniently and accurately, reducing the possibility of input errors and improving input efficiency.

[0030] When dynamically embedding the QML virtual keyboard into the QWidget application interface, the layout controller adaptively adjusts based on the current device's screen resolution and orientation. When the screen orientation changes from landscape to portrait, the layout controller recalculates the display position and size of the QML virtual keyboard relative to the input control that has gained focus, ensuring that the keyboard can be displayed in different screen orientations. For high-resolution screens, the size and spacing of the keyboard keys are increased. This avoids issues such as incomplete keyboard display and obscuring other interface elements. Increasing the size and spacing of the keyboard keys on high-resolution screens also improves the accuracy of touch operations, providing users with a better visual and operational experience.

[0031] The event converter, when converting input operations from the QML virtual keyboard into input events for QWidget input controls, features input validation. Before converting the input event, the event converter validates the input content. If the input content does not meet the rules of the input control, the event converter prevents the transmission of the input event and can send error information back to the QML virtual keyboard via a communication bridge, displaying prompt text on the keyboard to remind the user to re-enter the correct content. This ensures the legality and accuracy of the input data. For input controls with specific input rules, such as password and numeric input boxes, the input validation function effectively prevents users from entering incorrect content, reducing subsequent data processing and error correction costs and improving system stability and reliability.

[0032] It also includes a history input record module, which stores the user's historical input content on the QML virtual keyboard. The history input record module categorizes and stores historical inputs according to the type of input control and the time of input. When the user gains focus on the same type of input control again and triggers the QML virtual keyboard display, the historical input list of that type of input control is retrieved from the history input record module through the communication bridge and displayed on the QML virtual keyboard. Users can quickly select previously entered content, avoiding the tedious operation of repetitive input. Especially when it is necessary to frequently input the same or similar content, it can significantly save time and effort.

[0033] Example 2: An embedded QT virtual keyboard system based on a QWidget container includes a keyboard UI building module for implementing step S101, generating a reusable keyboard widget; a focus listening module for implementing step S102, listening for and determining whether the keyboard needs to pop up; a layout management module for implementing step S103, responsible for the positioning, embedding, and display of the keyboard; and an event injection module for implementing step S104, converting virtual key operations into standard keyboard events. Each module has a clear division of labor and works collaboratively to realize the basic functions of an embedded QT virtual keyboard based on a QWidget container, giving the system good scalability and maintainability, facilitating subsequent functional upgrades and optimizations.

[0034] It also includes an input validation module: before the event injection module converts virtual key operations into standard keyboard events, the input content is validated. For different types of input controls, the input validation module checks each input character according to preset rules. If the input content does not conform to the rules, the input validation module will prevent the further transmission of the input event. It can also display error messages on the virtual keyboard through interaction with the keyboard UI construction module, which enhances the input accuracy and stability of the system. The interaction between the input validation module and the keyboard UI construction module can promptly provide error information to the user, guide the user to input the correct content, avoid invalid input and erroneous data, and improve the overall quality of the system.

[0035] The keyboard UI building module can load keyboard layout files for different languages ​​based on user selections and generate virtual keyboard widgets for the corresponding languages. When displaying the virtual keyboard, the layout management module automatically adjusts the character display and layout structure of the keyboard according to the selected language to adapt to the character characteristics and input habits of different languages. The system has multilingual support capabilities, which can meet the input needs of different users in different language environments, adapt to the character characteristics and input habits of different languages, provide users with a more user-friendly and convenient input experience, and expand the application scope and user base of the system.

[0036] The present invention provides a method for implementing an embedded QT virtual keyboard based on a QWidget container, comprising the following steps: S101: Create a component that can be used for Quick and QOBJECT interaction. Create a class that inherits from QObject, including but not limited to QmlWidgetKeyboardBridge. Inside this component, implement the interface for hiding and showing the QT virtual keyboard, and get the input text of the QT virtual keyboard for this class implementation. S102: Establish a mechanism to associate input focus with the keyboard. By overriding the QWidget's event filter, the application's focus change event is listened to globally. When any QWidget is detected to have gained focus, the logic of the QT virtual keyboard is handled, and the QT virtual keyboard is hidden or shown. When a non-QQuickWidget area is clicked, the virtual keyboard is notified to be hidden through the event filter. When the user clicks the QML input box embedded in the QQuickWidget, the Qt virtual keyboard is shown. S103: Dynamic positioning and embedded display. Use QQuickWidget to embed the QML virtual keyboard as a child component into QWidget. Add the QmlWidgetKeyboardBridge component created in step S101 as a component to QML. Through QQuickWidget layout calculation, dynamically adjust the position of the input box to the bottom of the display screen without obscuring the input control and QWidget itself. S104: Simulated keyboard event injection. When the user clicks the QML text input box embedded in QQuickWidget, the virtual keyboard is dynamically brought up and the position of the input box is adjusted. The Qt virtual keyboard is operated, and after the relevant text is entered, the user can click on a non-QQuickWidget area to collapse the Qt virtual keyboard or click on the collapse button on the Qt virtual keyboard. The interface exposed by QmlWidgetKeyboardBridge in S101 obtains the content entered by the Qt virtual keyboard through signals and slots to complete the input.

[0037] This invention abandons the traditional independent window or specific frame keyboard, implementing the virtual keyboard as one or more standard QWidget controls. Since the keyboard itself is QML nested in QQuickWidget, it can be flexibly integrated with the application interface through Qt's layout managers (QHBoxLayout, QGridLayout) just like any other button or text box. The virtual keyboard is dynamically integrated into the window layout of the main application through Qt's layout managers, achieving seamless integration and dynamic arrangement with the business logic UI. It does not rely on the official Qt virtual keyboard implementation, but independently implements a stable, embedded virtual keyboard. This keyboard is based on the QWidget container, which can not only run stably in the Wayland environment, but also seamlessly compatible with other Qt plugin platforms. The virtual keyboard component is independent of the input method service provided by the operating system, enabling the application to complete text input without relying on external input method services on various Qt plugin platforms, including Wayland, linuxfb, xcb, and eglfs.

[0038] Obviously, the embodiments described above are merely some embodiments of the present invention, not all embodiments. The accompanying drawings show preferred embodiments of the present invention, but do not limit the patent scope of the present invention. The present invention can be implemented in many different forms; rather, these embodiments are provided to provide a more thorough and complete understanding of the disclosure of the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the patent protection scope of this invention.

Claims

1. A method for implementing an embedded QT virtual keyboard based on a QWidget container, characterized in that, Includes the following steps: S101. Establish a communication bridge to enable bidirectional transmission of commands and data between the QML virtual keyboard and the QWidget application; S102. Set a focus response mechanism to control the display and hiding of the QML virtual keyboard through the communication bridge according to the focus state of the QWidget input control; S103. Using a layout controller, the QML virtual keyboard is dynamically embedded into the QWidget application interface, and its position is displayed relative to the input control that currently has focus. S104. Using an event converter, the input operation of the QML virtual keyboard is converted into the input event of the QWidget input control.

2. The method for implementing an embedded QT virtual keyboard based on a QWidget container according to claim 1, characterized in that, The communication bridge is a C++ class based on the Qt meta-object system. It completes the bidirectional transmission by exposing callable interfaces to the QML environment and providing a signal transmission mechanism to the QWidget environment.

3. The method for implementing an embedded QT virtual keyboard based on a QWidget container according to claim 2, characterized in that, The focus response mechanism is implemented by installing a global event filter for the QWidget application.

4. The method for implementing an embedded QT virtual keyboard based on a QWidget container according to claim 3, characterized in that, When the global event filter detects a focus acquisition event, it not only sends a keyboard display command to the QML environment through the communication bridge, but also records the type information of the input control that has acquired focus. The type information includes, but is not limited to, text input boxes, password input boxes, and numeric input boxes. When different types of input controls trigger the display of the QML virtual keyboard, they can pass parameters to the QML environment so that the QML virtual keyboard can display the corresponding key layout according to the type of input control.

5. The method for implementing an embedded QT virtual keyboard based on a QWidget container according to claim 4, characterized in that, When dynamically embedding the QML virtual keyboard into the QWidget application interface, the layout controller will adaptively adjust according to the current screen resolution and screen orientation of the device. When the screen orientation changes from landscape to portrait, the layout controller will recalculate the display position and size of the QML virtual keyboard relative to the input control that has gained focus, to ensure that the keyboard can be displayed in different screen orientations. For high-resolution screens, the size and spacing of the keyboard keys will be increased.

6. The method for implementing an embedded QT virtual keyboard based on a QWidget container according to claim 5, characterized in that, The event converter has an input validation function when converting the input operation of the QML virtual keyboard into the input event of the QWidget input control. The event converter will validate the input content before converting the input event. If the input content does not meet the rule requirements of the input control, the event converter will prevent the transmission of the input event and can send error information to the QML virtual keyboard through the communication bridge, display prompt text on the keyboard, and prompt the user to re-enter the correct content.

7. The method for implementing an embedded QT virtual keyboard based on a QWidget container according to claim 6, characterized in that, It also includes a history input record module, which stores the user's historical input content on the QML virtual keyboard. The history input record module categorizes and stores historical inputs according to the type of input control and the input time. When the user gains focus on the same type of input control again and triggers the QML virtual keyboard display, the historical input list of that type of input control is retrieved from the history input record module through the communication bridge and displayed on the QML virtual keyboard.

8. An embedded QT virtual keyboard system based on a QWidget container, using the embedded QT virtual keyboard implementation method based on a QWidget container as described in claim 7, characterized in that, The system includes a keyboard UI building module for implementing step S101 and generating a reusable keyboard widget; a focus listening module for implementing step S102 and listening for and determining whether the keyboard needs to be displayed; a layout management module for implementing step S103 and being responsible for the positioning, embedding, and display of the keyboard; and an event injection module for implementing step S104 and converting virtual key operations into standard keyboard events.

9. An embedded QT virtual keyboard system based on a QWidget container according to claim 8, characterized in that, It also includes an input validation module: before the event injection module converts virtual key operations into standard keyboard events, the input content is validated. For different types of input controls, the input validation module checks the input characters one by one according to preset rules. If the input content does not conform to the rules, the input validation module will prevent the further transmission of the input event, and can display error prompts on the virtual keyboard through interaction with the keyboard UI building module.

10. An embedded QT virtual keyboard system based on a QWidget container according to claim 8, characterized in that, The keyboard UI building module can load keyboard layout files for different languages ​​according to user selection settings and generate virtual keyboard widgets for the corresponding languages. When displaying the virtual keyboard, the layout management module will automatically adjust the character display and layout structure of the keyboard according to the selected language to adapt to the character characteristics and input habits of different languages.