Use of custom controls in Qt Designer (promotion method and plug-in method)

Source: Internet
Author: User
Tags qt designer

  • To use the Qt custom Widget in the Designer. However, I do not want to repeat the promotion and plug-in methods for basic usage, because the Using Custom Widgets with Qt Designer in Manual is already clear.

  • Use designer
    Qt users may experience three stages:

    Just getting started with Qt, drag and drop in the designer, and an interface is formed. It is quite convenient (but many netizens were quite uncomfortable with layout during their first contact)
    After getting familiar with this, I feel that designer is cumbersome, for example:
    It seems that the Drag Control in the designer is not easy to control in the code. Although QLayout is used
    After accessing the custom control, it is difficult to use the custom control in the designer.
    This is a set of things that do not like desinger generation. ui file, and then uic generation ui_xxx.h file.
    ...
    After a while, I found that the designer is really convenient. In addition, it is very easy to use custom controls in designer through the lift method. In addition, the problems in the previous phase are not a problem.
    Custom Controls
    Consider the following situations:

    Derived an LED light control from QWidget: HLed
    A variable: HBaseSpinBox is derived from QSpinBox.
    Derived from QLabel: HLabel
    ...
    Well, nothing special

    If it is used in the code, include the header file and use it directly. It is no different from standard controls.
    If you want to use it in designer, Drag and Drop QWidget, QSpinBox, and QLabel respectively, right-click to promote...
    Upgrade vs plug-in
    Are there any differences between the two methods? What is the difference?

    First, consider how we use designer (this does not consider. ui dynamic loading ):

    Open designer, Drag and Drop controls, apply layout, and Set Properties
    Save and generate XXX. ui File
    Call uic to preprocess XXX. ui into ui_XXX.h
    Call the C ++ compiler to compile these *. h, *. cpp

    Note: If you write a plug-in, it is only useful in the first step. What is the purpose:

    The plug-in contains the includeFile () header file of the Class name. (For comparison, manually enter the two items when using the lift method)

    Implement the control contained in the plug-in
    Therefore, you can see the actual display of the control in the designer. (In comparison, an improvement method requires a substitute, which is generally its base class)
    You can detect the attributes and display them in the property editor. (For comparison, you can directly add an attribute in the Attribute Editor and add another big plus sign, right ?)
    ...
    In the final analysis, there is no essential difference between the plug-in method and the improvement method. Both generate a. ui file, and the use of this file has nothing to do with the plug-in.

    What else...
    None of the above seems to be interesting, because Manual makes it clear that the above things can be obtained through the Upgrade Method and plug-in method.

    However, it may be a bit interesting to consider:

    I derived a HDoubleSpinBox from QStackedWidget. However, in designer, I want to see a QDoubleSpinBox instead of a stacked widget.
    I derived an HLabelButton from QLabel. However, in designer, I want to see a QToolButton instead of a QLabel.
    ...
    Can the plug-in method be implemented?

    Yes, as long as you have the createWidget () of the plug-in create a QDoubleSpinBox or QToolButton

    Can the promotion method be implemented?

    Yes. We need to select a base class when upgrading. This base class can be selected at will and displayed as a replacement.

    (Note: many details are ignored in this article, so it may not be misleading ...)

    From: 1 + 1 = 2 simple, my hut...

  •  

Related Article

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.