In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 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 dynamic properties in Qt. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
I. Preface
As mentioned before, Qt's attribute mechanism is extremely powerful, this time the dynamic attribute function is to let him explode, it is hard to imagine that only one line of code can widget- > setProperty ("value", value); yes, it is as simple as that, calling the weak attribute mechanism can directly control all the properties in the control. The designer of this mechanism is absolutely a genius and knelt directly. As for the specific bottom layer is how to achieve, this can be ignored, and do not have much energy to study the source code of Qt, that source code is very large, the fastest way to study the source code is to search for the corresponding files directly. In addition to providing text box input values to dynamically change the control properties, the designer also provides a variety of ways to obtain data sources, such as sliding bar, random simulation data, serial port data collection, network data collection, database data collection and so on. Here we have to mention a powerful technique: QLabel has three ways to set up the text, master the attribute system of Qt, citing examples, can make a lot of effects.
Ui- > label- > setStyleSheet ("qproperty-text:hello;"); ui- > label- > setProperty ("text", "hello"); ui- > label- > setText ("hello"); II. Realized functions
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. The core code void frmMain::initForm () {/ / initializes the Chinese-English attribute comparison table QtPropertyName::initMap (); / / the setting does not close buttons ui- > dockWidgetControl- > setFixedWidth; ui- > dockWidgetData- > setFixedWidth; ui- > dockWidgetProperty- > setFixedWidth (220); ui- > dockWidgetControl- > setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); ui- > dockWidgetProperty- > setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable) Ui- > dockWidgetData- > setFeatures (QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); this- > tabifyDockWidget (ui- > dockWidgetControl, ui- > dockWidgetData); ui- > dockWidgetControl- > raise (); / / numerical change signal connect (ui- > dockWidgetContentsData, SIGNAL (valueChanged (int)), this, SLOT (valueChanged (int)) of the bound data source form; / / allow dragging to receive this- > setAcceptDrops (true); bgPix = QPixmap (": / image/bg.png") / / Center display form int frmX = this- > width (); int frmY = this- > height (); QDesktopWidget w; int deskWidth = w.availableGeometry (). Width (); int deskHeight = w.availableGeometry (). Height (); QPoint movePoint (deskWidth / 2-frmX / 2, deskHeight / 2-frmY / 2); this- > move (movePoint); / / initialize the random number seed QTime t = QTime::currentTime () Qsrand (t.msec () + t.second () * 1000); / timer simulates random values assigned to controls timer = new QTimer (this); connect (timer, SIGNAL (timeout ()), this, SLOT (setValue (); timer- > setInterval (2000);} void frmMain::setValue () {int value = qrand ()% 100; valueChanged (value);} void frmMain::valueChanged (int value) {QList widgets = ui- > centralwidget- > findChildren () Foreach (QWidget * widget, widgets) {widget- > setProperty ("value", value);}} this is the end of the article on "how to achieve dynamic attributes in Qt". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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: 0
*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.