Write QT designer custom controls (1) -- how to create and use QT Custom Controls

Source: Internet
Author: User
Tags qt designer

When using QT designer to design the form interface, we can use the form control in the widget box to easily draw the interface, such as dragging a button and a text editor. Although the controls in QT designer can meet most of our needs, sometimes some special requirements are also generated. For example, in an input box, we need to enter the longitude and latitude, in this case, there are two input methods: decimal form and second form. At this time, only one simple lineedit can not meet the requirements. We imagine constructing an input control that supports floating-point numbers and has an attribute that can be changed to the input form of longitude and latitude. If we need to input longitude and latitude on multiple forms, it is very convenient to construct such a control. The following example describes how to create a custom form control.

Step 1: create a custom control project for qtdesigner

Open QT creator and create a QT designer custom control, as shown in:

 

Follow the prompts in the Wizard to create a project named loglatedit. The project directory is shown in:

 

Step 2: Compile the Control Project

In order to write the entire custom control, we will not make any changes, switch to the release version, and compile it directly.

Step 3: deploy the plug-in

After compilation, copy the generated DLL file and Lib file to the QT plug-in directory under the output directory. Take QT 4.8.4 as an example, under the installation directory D: \ QT \ 4.8.4 of QT 4.8.4, find the Plugins directory, find the designer directory, and put the DLL and Lib in the directory. The complete path is: D: \ QT \ 4.8.4 \ plugins \ designer. Start designer.exe under D: \ QT \ 4.8.4 \ binand create a form. Then, we will find our own loglatedit control in the widget box on the left, we can drag our own controls to the form like other controls, as shown in:

 

If the custom control does not appear in the widgetbox, you can click the "Help-about plug-in" menu to open the plug-in information dialog box and click "refresh, as long as you have not forgotten to copy the DLL and Lib files to the correct location, the plug-in will automatically identify and load them. The same applies to other versions of QT. For example, I have installed several versions of QT on my computer. The same applies to other versions of QT, you only need to place the DLL and Lib files generated by the plug-in project to the plug-in directory of the corresponding version.

At this point, we have clarified how to create a custom control and how to deploy, load, and use the custom control. Next we will write the required controls. For those who only want to understand the development process of custom controls, now they know how to do it. You can skip the following content.

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.