Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Qt interface framework

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "how to use the Qt interface framework", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use the Qt interface framework.

I. Preface

Qt is basically a super-large one-stop GUI supermarket framework, with all kinds of controls you need, such as buttons, labels, text boxes, drop-down boxes, progress bars, etc., even if you don't have them, you can customize the controls. As a powerful GUI interface framework, it takes time to learn well. No one can do it overnight. There are two points at the core of the interface: layout and color matching. Generally speaking, this is the work of artists, but looking at the companies where most programmers work in China, there are basically no artists, which is very pitiful, requiring programmers to cover everything by themselves, from requirements analysis to detailed design to code writing to interface design to after-sales maintenance.

Qt layout provides horizontal layout, vertical layout, table layout, grid layout, mainly these four, learned these layouts is actually not enough, many beginners will find that can not achieve the desired effect, in fact, but also to cooperate with two powerful things, that is, the stretching strategy of the control itself sizePolicy plus spring spacer, in which the stretching strategy includes four elements Horizontal strategy, vertical strategy, horizontal extension, vertical extension. In a complete project with an interface, you definitely need to use these things to make a pleasing interface.

Qt's color should be QSS invincible, this thing is said to be a subset of CSS2, in theory contains all the writing of CSS2, but now CSS3 popular, QSS does not support CSS3, it is estimated that to rewrite QSS parser on the line, the code should be huge, may be the main official push qml, it is estimated that there is no such plan to update QSS to support CSS3, if one day support CSS3, then the effect of the absolute universe first. I have opened up 3 sets of QSS skin styles.

II. Functional features

Collect data port, support serial port + network port, serial port support free setting of serial number + baud rate, network support free setting of IP address + communication port, each port supports collection cycle, default one address per second, support setting communication timeout times, default 3 times, support maximum reconnection time, used to re-read offline devices.

Controller information, you can add the controller name, select the controller address + controller model, and set the number of detectors under the controller.

Detector information, can add tag, free to choose detector type, gas type, gas symbol, high reported value, low reported value, buffer value, clear zero value, whether enabled, alarm sound, background map, storage cycle, numerical conversion decimal places, alarm delay time, alarm type (HH,LL,HL) and so on.

Controller model + detector type + gas type + gas symbol, all can be configured freely.

Maps can be imported and deleted, and all detectors can be dragged and saved freely.

Port information + controller information + detector information, support import and export + export to excel+ printing.

Run record + alarm record + user record, support multi-condition combination query, such as time period + controller + detector, etc., all records can be exported to excel+ printing.

Records exported to excel support all versions of table files such as excel+wps and do not rely on software such as excel.

You can delete data within a specified time range, support automatic cleaning of early data, and set the maximum number of saved records.

Support alarm short message forwarding, support multiple receiving mobile phone numbers, you can set the sending interval, such as instant sending or sending all alarm messages once every 6 hours, the text message content is too long, automatically split multiple text messages.

Support alarm email forwarding, support multiple receiving mailboxes, can set sending interval, such as immediate sending or sending all alarm messages once every 6 hours, support attachment sending.

Overreport color + underreport color + normal color + 0 value color + curve background + curve color, etc., are free to choose.

The Chinese title + English title + logo path + copyright of the software can be set freely.

Provide switch settings for boot operation + alarm sound + automatic login + remember password and so on.

Alarm sound can be set to play the number of times, the interface provides 17 kinds of skin file selection.

Cloud data synchronization is supported, and the information of cloud database can be set, such as database name, user name + password, etc.

Support network forwarding and network reception, after the network reception is turned on, the software receives data from udp for analysis. Network forwarding supports multiple target IP, so it realizes the software of local collection, and freely transfers the data to the client to view the detector data at any time.

Automatically remember the user's last stay in the interface + other information, restart and apply automatically.

The alarm automatically switches to the corresponding map, and the detector button flashes.

Double-click the detector icon to control it back.

Support user rights management, administrator + operator two categories, user login + user exit, can remember the password and automatic login, more than three error messages and close the program.

Support four monitoring modes, equipment panel monitoring + map monitoring + table data monitoring + curve data monitoring, free to switch, four synchronous applications.

Support alarm relay linkage, a tag can link multiple modules and relay numbers across serial ports, and support many-to-many.

The local data store supports sqlite+mysql and remote data synchronization to the cloud database. Automatically reconnect.

The data collected by the local device is uploaded to the cloud in real time so that it can be extracted by other methods such as APP or web.

Two kinds of data sources are supported, one is serial port and network to collect equipment data through protocol, the other is database collection. The database acquisition mode can be used as a general system.

Comes with a device simulation tool that supports 16 device data simulations, as well as database data simulations to test data when there is no device.

The default communication protocol uses modbus protocol, and later increases the support of mqtt and other Internet of things protocols to make a general system.

Supports all windows operating systems + linux operating systems and other operating systems.

Third, effect picture

Core code # include "frmview.h" # include "ui_frmview.h" # include "quiwidget.h" # include "dbhelper.h" # include "iconfont.h" # include "deviceserver.h" # include "devicehelper.h" # include "alarmlink.h" # include "soundapi.h" # include "deviceserver.h" # include "frmviewdevice.h" # include "frmviewmap.h" # include "frmviewdata.h" # include "frmviewplot.h" # include "frmdevicecontrol.h" frmView::frmView (QWidget * parent): QWidget (parent) Ui (new Ui::frmView) {ui- > setupUi (this) This- > initForm (); this- > initControl (); QTimer::singleShot (1000, this, SLOT (initServer ());} frmView::~frmView () {delete ui;} void frmView::initForm () {ui- > navTitleTable- > setText ("Police Intelligence"); ui- > navTitleTable- > setLeftIcon (0xf108); ui- > navTitleTable- > setRightIcon4 (0xf1f7); ui- > navTitleTable- > setRightIcon5 (0xf1f8); ui- > navTitleTree- > setText ("device list") Ui- > navTitleTree- > setLeftIcon (0xf0e8); ui- > navTitleTree- > setRightIcon5 (0xf021); ui- > navTitleList- > setText ("Map list"); ui- > navTitleList- > setLeftIcon (0xf0e8); ui- > navTitleList- > setRightIcon5 (0xf021); ui- > widgetLeft- > setFixedWidth (App::LeftWidth); ui- > widgetRight- > setFixedWidth (App::RightWidth); connect (ui- > navTitleTable, SIGNAL (mousePressed (int)), this, SLOT (mousePressed (mousePressed)) Connect (AppEvent::Instance (), SIGNAL (doubleClicked (ButtonDefence *)), this, SLOT (doubleClicked (ButtonDefence *)); frmViewDevice * viewDevice = new frmViewDevice; ui- > stackedWidget- > addWidget (viewDevice); frmViewMap * viewMap = new frmViewMap; ui- > stackedWidget- > addWidget (viewMap); frmViewData * viewData = new frmViewData; ui- > stackedWidget- > addWidget (viewData); frmViewPlot * viewPlot = new frmViewPlot; ui- > stackedWidget- > addWidget (viewPlot) Connect (this, SIGNAL (itemClicked (QString)), viewDevice, SLOT (itemClicked (QString)); connect (DeviceServer::Instance (), SIGNAL (receiveAlarm (QString, QString, quint8)), this, SLOT (receiveAlarm (QString, QString, quint8)); DeviceHelper::setTableData (viewData- > getTable ()); DeviceHelper::setTableWidget (ui- > tableWidget); DeviceHelper::setTreeWidget (ui- > treeWidget); DeviceHelper::setListWidget (ui- > listWidget); DeviceHelper::setPanelWidget (viewDevice- > viewDevice- ()) DeviceHelper::setLabel (viewMap- > getLabel ());} void frmView::initTree () {DeviceHelper::initDeviceTree (); DeviceHelper::initDeviceStyle ();} void frmView::initControl () {DeviceHelper::initDeviceData (); DeviceHelper::initDeviceTable (); DeviceHelper::initDeviceTree (); DeviceHelper::initDeviceMap (); DeviceHelper::initDevicePanel (); DeviceHelper::initDeviceButton () If (ui- > listWidget- > count () > 0) {ui- > listWidget- > setCurrentRow (0); on_listWidget_pressed ();}} void frmView::initServer () {/ / start device parsing DeviceServer::Instance ()-> init (); DeviceServer::Instance ()-> start () } void frmView::mousePressed (int index) {if (index = = 5) {/ / change the sound icon and stop the alarm sound ui- > navTitleTable- > setRightIcon4 (0xf1f7); SoundAPI::Instance ()-> stop (); if (App::WorkMode = = 0) {AlarmLink::Instance ()-> reset () }} else if (index = = 6) {/ / clear temporary message DeviceHelper::clearMsg () }} void frmView::doubleClicked (ButtonDefence * btn) {if (App::CurrentUserType.contains ("administrator")) {if (btn- > getButtonStatus () = = ButtonDefence::ButtonStatus_Error) {/ / double-click to reconnect all devices under the current port QString portName = DBHelper::getPortName (btn- > property ("deviceName"). ToString (); DeviceServer::Instance ()-> readValue (portName, 255, true) } else {/ / popup details QString positionID = btn- > property ("positionID"). ToString (); frmDeviceControl::Instance ()-> setPositionID (positionID); frmDeviceControl::Instance ()-> show ();} void frmView::on_listWidget_pressed () {int row = ui- > listWidget- > currentRow (); if (row)

< 0) { return; } DeviceHelper::initDeviceMapCurrent(DBData::MapNames.at(row));}void frmView::on_treeWidget_itemPressed(QTreeWidgetItem *item, int column){ if (item->

Parent ()! = 0) {emit itemClicked (item- > text (column));}} void frmView::setIndex (int index) {ui- > stackedWidget- > setCurrentIndex (index); bool visible = (index = = 0 | index = = 2); ui- > widgetLeft- > setVisible (! (index = = 3)); ui- > widgetRight- > setVisible (! (index = = 3)); ui- > navTitleTree- > setVisible (visible); ui- > treeWidget- > setVisible (visible); ui- > navTitleList- > setVisible (! visible) Ui- > listWidget- > setVisible (! visible);} void frmView::receiveAlarm (const QString & deviceName, const QString & positionID, quint8 alarmType) {if (alarmType = = 0 | | alarmType = = 2) {ui- > navTitleTable- > setRightIcon4 (0xf0a2);} else {ui- > navTitleTable- > setRightIcon4 (0xf1f7);}} so far, I believe you have a better understanding of "how to use the Qt interface framework", you might as well do it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report