In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to achieve user attributes in Qt. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
I. Preface
The user attribute is a new function added later. If the custom control uses the Q_PROPERTY modified property, it will be automatically recognized in the property bar, which is generally called the control property. In the configuration design software, it is not enough to have the control property of the control itself. After all, these properties are only based on appearance and can not represent the properties of a device. Therefore, it is necessary to add user attributes in addition to this control property to store the device properties associated with the control, such as device number, device name, geographical location and other information, which, like the control properties, can be imported and exported to xml files, and can support multiple user attributes. Users can fill in their own names and values, and both names and values can be described in Chinese. In order to distinguish between user attributes and control properties in the xml file, the user attributes are specially prefixed with the user- prefix, so that when reading the xml file to load the control, those identified at the beginning of the user- are stored in the list of user properties of the control. Since the mechanism of user attributes, the existing function of the control has been greatly expanded, which is equivalent to binding N custom data. These user attributes can be directly set by setProperty, and then read through property. In order to support Chinese attribute names, convert them when you need to set properties: widget- > setProperty (name.toStdString (). C_str (), value).
Second, the functions realized
Automatically load all the controls in the plug-in file to generate a list, with more than 120 controls by default.
Drag to the canvas to automatically generate the corresponding control, WYSIWYG.
On the right side of the Chinese attribute bar, change the corresponding attributes immediately applied to the corresponding selected controls, intuitive and concise, very suitable for rookies to use.
The original attribute bar text translation mapping mechanism is extremely efficient, and it is very convenient to expand the attribute bar of other languages.
The properties of all controls are automatically extracted and displayed in the right property bar, including the enumerated value drop-down box.
Support manual selection of plug-in files, external import plug-in files.
You can export all control configuration information for the current canvas to a xml file.
You can manually select the xml file to open the control layout and automatically load the control according to the xml file.
Can pull the slider, check the analog data check box, text box input, three ways to generate data to apply all controls.
The control supports eight azimuth pull adjustments, adapts to any resolution, and fine-adjusts the position up and down the keyboard.
Through the serial port acquisition, network acquisition, database collection of three ways to set data.
The code is extremely concise, the comments are very detailed, and can be used as an embryonic form of configuration to expand more functions.
Pure Qt writing, support any Qt version + any compiler + any system.
Third, effect picture
4. Core code void frmMain::openFile (const QString & fileName) {/ / if the control list is not available, do not continue to if (ui- > listWidget- > count () = = 0) {return;} / / Open the file QFile file (fileName); if (! file.open (QFile::ReadOnly | QFile::Text)) {return;} / / populate the file into the dom container QDomDocument doc If (! doc.setContent (& file)) {file.close (); return;} file.close (); listSelect.clear (); listUserProperty.clear (); xmlName = fileName; / / clear the original control QList widgets = ui- > centralwidget- > findChildren (); qDeleteAll (widgets); widgets.clear (); / / first determine whether the root element is correct QDomElement docElem = doc.documentElement () If (docElem.tagName () = = "canvas") {QDomNode node = docElem.firstChild (); QDomElement element = node.toElement (); while (! node.isNull ()) {/ / Control name QString name = element.tagName () / / retrieve the index of the current control in the control list. If it does not exist, it means that the control in the configuration file does not exist int index = listNames.indexOf (name); if (index < 0) {continue;} / / stores the coordinate location and width height of the control int x, y, width, height / / Storage Custom Control property QList propertys; / / Storage Control Custom property QStringList userProperty; / / Node name is not empty to continue if (! name.isEmpty ()) {/ / traversal node attribute name and attribute value QDomNamedNodeMap attrs = element.attributes () For (int I = 0; I < attrs.count (); iTunes +) {QDomNode node = attrs.item (I); QString nodeName = node.nodeName (); QString nodeValue = node.nodeValue (); / / qDebug ()
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 227
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.