How to customize widgets in QT5

Source: Internet
Author: User
Tags config json qt designer
Lifting Method
QT assistance:using Custom Widgets with Qt Designer
eg. (Define a new qlable part)
1. Define a class
Class Label:public base, public qlabel//can support multiple inheritance
2. Open the UI editor in Qt Creator, drag a qlable to redeem, promote, enter the class name of the promoted label, tick all include, add, promote success.


plug-in method
QT assistance:creating Custom Widgets for Qt Designer
1, as with the lifting method, it is necessary to create a new component class
Class Analogclock:public Qwidget
2, create a plug-in class
Class Analogclockplugin:public Qobject, public qdesignercustomwidgetinterface
{
Q_object
Q_plugin_metadata (IID "Org.qt-project.qt.qdesignercustomwidgetinterface" FILE "Analogclock.json")
Q_interfaces (Qdesignercustomwidgetinterface)
Public
Explicit Analogclockplugin (Qobject *parent = 0);
......
};
and implement its related functions in its CPP.
3. Modify the. Pro File
......
CONFIG + = Plugin
CONFIG + = Designer
CONFIG + = Debug_and_release
TEMPLATE = Lib
QT + = Widgets Designer
SOURCES + = \
Analogclock.cpp \
Analogclockplugin.cpp
HEADERS + = \
Analogclock.h \
Analogclockplugin.h
Other_files + = Analogclock.json
Target.path = $$[qt_install_plugins]/designer

Installs + = target

...... 4. Build an empty Analogclock.json file in the project file directory

5. Compile the build. dll file and place it under C:\Qt\Qt5.2.0\5.2.0\msvc2012_64_opengl\plugins\designer to use the custom plugin in Qt Designer.

Note: If you need to use this plugin in Qt Creator, since the two parts of Qt SDK for Windows are compiled by a different compilation environment, Qtcreator is compiled by MSVC, the QT Library is compiled by MinGW, so it needs to be copied to C:\Qt\ Qt5.2.0\tools\qtcreator\bin\plugins\designer, there are several ways to solve this problem:

1) Download the QT creator source code and compile it in Qt Creator with MinGW
2) Compile the plugin under Visual Studio build the plugin with Visual Studio
3) compile QT creator source code, but turn the build key checking off

You can then open the project's interface file (*.ui) in Qtcreator, at which point Qtcreator allows you to edit the UI file using the integrated Qtdesigner, then open the menu item "Tools, Interface Editor->about Qt Designer plugins ... "to see which plug-ins have been loaded successfully and which have not been loaded successfully (in a separate run Qtdesigner, open the Help, about plugins menu to see if the plug-in was loaded successfully).

Reference article:

http://blog.csdn.net/ubiter/article/details/12757817

http://www.yekezhong.com/704

http://blog.csdn.net/dbzhang800/article/details/6871693

http://blog.csdn.net/yangxiao_0203/article/details/6896707

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.