《QT实用小工具·三十一》基于QT开发的访客管理平台demo2

devtools/2024/9/24 8:21:25/

1、概述
源码放在文章末尾

该项目为访客管理平台demo,包含主界面、系统设置、警情查询、调试帮助、用户退出功能。
在这里插入图片描述
项目部分代码如下:

#pragma execution_character_set("utf-8")#include "frmmain.h"
#include "ui_frmmain.h"
#include "iconhelper.h"
#include "qthelper.h"frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain)
{ui->setupUi(this);this->initForm();this->initStyle();this->initLeftMain();this->initLeftConfig();
}frmMain::~frmMain()
{delete ui;
}bool frmMain::eventFilter(QObject *watched, QEvent *event)
{if (watched == ui->widgetTitle) {if (event->type() == QEvent::MouseButtonDblClick) {on_btnMenu_Max_clicked();}}return QWidget::eventFilter(watched, event);
}void frmMain::getQssColor(const QString &qss, const QString &flag, QString &color)
{int index = qss.indexOf(flag);if (index >= 0) {color = qss.mid(index + flag.length(), 7);}//qDebug() << TIMEMS << flag << color;
}void frmMain::getQssColor(const QString &qss, QString &textColor, QString &panelColor,QString &borderColor, QString &normalColorStart, QString &normalColorEnd,QString &darkColorStart, QString &darkColorEnd, QString &highColor)
{getQssColor(qss, "TextColor:", textColor);getQssColor(qss, "PanelColor:", panelColor);getQssColor(qss, "BorderColor:", borderColor);getQssColor(qss, "NormalColorStart:", normalColorStart);getQssColor(qss, "NormalColorEnd:", normalColorEnd);getQssColor(qss, "DarkColorStart:", darkColorStart);getQssColor(qss, "DarkColorEnd:", darkColorEnd);getQssColor(qss, "HighColor:", highColor);
}void frmMain::initForm()
{//设置无边框QtHelper::setFramelessForm(this);//设置图标IconHelper::setIcon(ui->labIco, 0xf073, 30);IconHelper::setIcon(ui->btnMenu_Min, 0xf068);IconHelper::setIcon(ui->btnMenu_Max, 0xf067);IconHelper::setIcon(ui->btnMenu_Close, 0xf00d);//ui->widgetMenu->setVisible(false);ui->widgetTitle->setProperty("form", "title");//关联事件过滤器用于双击放大ui->widgetTitle->installEventFilter(this);ui->widgetTop->setProperty("nav", "top");QFont font;font.setPixelSize(25);ui->labTitle->setFont(font);ui->labTitle->setText("智能访客管理平台");this->setWindowTitle(ui->labTitle->text());ui->stackedWidget->setStyleSheet("QLabel{font:60px;}");QSize icoSize(32, 32);int icoWidth = 85;//设置顶部导航按钮QList<QAbstractButton *> tbtns = ui->widgetTop->findChildren<QAbstractButton *>();foreach (QAbstractButton *btn, tbtns) {btn->setIconSize(icoSize);btn->setMinimumWidth(icoWidth);btn->setCheckable(true);connect(btn, SIGNAL(clicked()), this, SLOT(buttonClick()));}ui->btnMain->click();ui->widgetLeftMain->setProperty("flag", "left");ui->widgetLeftConfig->setProperty("flag", "left");ui->page1->setStyleSheet(QString("QWidget[flag=\"left\"] QAbstractButton{min-height:%1px;max-height:%1px;}").arg(60));ui->page2->setStyleSheet(QString("QWidget[flag=\"left\"] QAbstractButton{min-height:%1px;max-height:%1px;}").arg(25));
}void frmMain::initStyle()
{//加载样式表QString qss = QtHelper::getStyle(":/qss/blacksoft.css");if (!qss.isEmpty()) {QString paletteColor = qss.mid(20, 7);qApp->setPalette(QPalette(QColor(paletteColor)));qApp->setStyleSheet(qss);}//先从样式表中取出对应的颜色QString textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor;getQssColor(qss, textColor, panelColor, borderColor, normalColorStart, normalColorEnd, darkColorStart, darkColorEnd, highColor);//将对应颜色设置到控件this->borderColor = highColor;this->normalBgColor = normalColorStart;this->darkBgColor = panelColor;this->normalTextColor = textColor;this->darkTextColor = normalTextColor;
}void frmMain::buttonClick()
{QAbstractButton *b = (QAbstractButton *)sender();QString name = b->text();QList<QAbstractButton *> tbtns = ui->widgetTop->findChildren<QAbstractButton *>();foreach (QAbstractButton *btn, tbtns) {btn->setChecked(btn == b);}if (name == "主界面") {ui->stackedWidget->setCurrentIndex(0);} else if (name == "系统设置") {ui->stackedWidget->setCurrentIndex(1);} else if (name == "警情查询") {ui->stackedWidget->setCurrentIndex(2);} else if (name == "调试帮助") {ui->stackedWidget->setCurrentIndex(3);} else if (name == "用户退出") {exit(0);}
}void frmMain::initLeftMain()
{iconsMain << 0xf030 << 0xf03e << 0xf247;btnsMain << ui->tbtnMain1 << ui->tbtnMain2 << ui->tbtnMain3;for (int i = 0; i < btnsMain.count(); ++i) {QToolButton *btn = (QToolButton *)btnsMain.at(i);btn->setCheckable(true);btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);connect(btn, SIGNAL(clicked(bool)), this, SLOT(leftMainClick()));}IconHelper::StyleColor styleColor;styleColor.position = "left";styleColor.iconSize = 18;styleColor.iconWidth = 35;styleColor.iconHeight = 25;styleColor.borderWidth = 4;styleColor.borderColor = borderColor;styleColor.setColor(normalBgColor, normalTextColor, darkBgColor, darkTextColor);IconHelper::setStyle(ui->widgetLeftMain, btnsMain, iconsMain, styleColor);ui->tbtnMain1->click();
}void frmMain::initLeftConfig()
{iconsConfig << 0xf031 << 0xf036 << 0xf249 << 0xf055 << 0xf05a << 0xf249;btnsConfig << ui->tbtnConfig1 << ui->tbtnConfig2 << ui->tbtnConfig3 << ui->tbtnConfig4 << ui->tbtnConfig5 << ui->tbtnConfig6;for (int i = 0; i < btnsConfig.count(); ++i) {QToolButton *btn = (QToolButton *)btnsConfig.at(i);btn->setCheckable(true);btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);connect(btn, SIGNAL(clicked(bool)), this, SLOT(leftConfigClick()));}IconHelper::StyleColor styleColor;styleColor.position = "left";styleColor.iconSize = 16;styleColor.iconWidth = 20;styleColor.iconHeight = 20;styleColor.borderWidth = 3;styleColor.borderColor = borderColor;styleColor.setColor(normalBgColor, normalTextColor, darkBgColor, darkTextColor);IconHelper::setStyle(ui->widgetLeftConfig, btnsConfig, iconsConfig, styleColor);ui->tbtnConfig1->click();
}void frmMain::leftMainClick()
{QAbstractButton *b = (QAbstractButton *)sender();QString name = b->text();for (int i = 0; i < btnsMain.count(); ++i) {QAbstractButton *btn = btnsMain.at(i);btn->setChecked(btn == b);}ui->lab1->setText(name);
}void frmMain::leftConfigClick()
{QToolButton *b = (QToolButton *)sender();QString name = b->text();for (int i = 0; i < btnsConfig.count(); ++i) {QAbstractButton *btn = btnsConfig.at(i);btn->setChecked(btn == b);}ui->lab2->setText(name);
}void frmMain::on_btnMenu_Min_clicked()
{showMinimized();
}void frmMain::on_btnMenu_Max_clicked()
{static bool max = false;static QRect location = this->geometry();if (max) {this->setGeometry(location);} else {location = this->geometry();this->setGeometry(QtHelper::getScreenRect());}this->setProperty("canMove", max);max = !max;
}void frmMain::on_btnMenu_Close_clicked()
{close();
}

源码下载


http://www.ppmy.cn/devtools/2621.html

相关文章

Flask前端页面文本框展示后端变量,路由函数内外两类

一、外&#xff01;路由函数外的前后端数据传输 Flask后端 ↓ 首先导入包&#xff0c;需要使用 后端&#xff1a;flask_socketio来进行路由外的数据传输&#xff0c; from flask_socketio import SocketIO, emit 前端&#xff1a;还有HTML头文件的设置。 <!DOCTYPE …

web server apache tomcat11-09-JNDI Datasource

前言 整理这个官方翻译的系列&#xff0c;原因是网上大部分的 tomcat 版本比较旧&#xff0c;此版本为 v11 最新的版本。 开源项目 从零手写实现 tomcat minicat 别称【嗅虎】心有猛虎&#xff0c;轻嗅蔷薇。 系列文章 web server apache tomcat11-01-官方文档入门介绍 web…

吴恩达llama课程笔记:第七课llama安全工具

羊驼Llama是当前最流行的开源大模型&#xff0c;其卓越的性能和广泛的应用领域使其成为业界瞩目的焦点。作为一款由Meta AI发布的开放且高效的大型基础语言模型&#xff0c;Llama拥有7B、13B和70B&#xff08;700亿&#xff09;三种版本&#xff0c;满足不同场景和需求。 吴恩…

13.C++常用的算法_查找算法

文章目录 遍历算法1. adjacent_find代码工程运行结果 2. binary_search()代码工程运行结果 3. count()代码工程运行结果 4. count_if()代码工程运行结果 遍历算法 1. adjacent_find 代码工程 查找相邻元素是否存在,不存在返回容器最后位置的迭代器#define _CRT_SECURE_NO_WA…

Rust 构建跨平台 GUI 的新选择

在现代软件开发过程中&#xff0c;用户界面&#xff08;GUI&#xff09;的设计与实现是不可或缺的一环。随着Rust编程语言的崛起&#xff0c;其安全性、性能和并发特性使其成为开发高质量GUI应用的理想选择。relm框架&#xff0c;作为Rust生态中的一员&#xff0c;提供了一种声…

【科研入门】评价指标AUC原理及实践

评价指标AUC原理及实践 目录 评价指标AUC原理及实践一、二分类评估指标1.1 混淆矩阵1.2 准确率 Accuracy定义公式局限性 1.3 精确率 Precision 和 召回率 Recall定义公式 1.4 阈值定义阈值的调整 1.5 ROC与AUC引入定义公式理解AUC算法 一、二分类评估指标 1.1 混淆矩阵 对于二…

【Entity Framework】闲话EF中批量配置

【Entity Framework】闲话EF中批量配置 文章目录 【Entity Framework】闲话EF中批量配置一、概述二、OnModelCreating中的批量配置元数据API的缺点 三、预先约定配置忽略类型默认类型映射预先约定配置的限制约定添加新约定替换现有约定约定实现注意事项 四、何时使用每种方法进…

docker 上达梦导入dump文件报错:本地编码:PG GBK,导入女件编码:PGGB18030

解决方案&#xff1a; 第一步进入达梦数据容器内部 docker exec -it fc316f88caff /bin/bash 第二步&#xff1a;在容器中 /opt/dmdbms/bin目录下 执行命令 cd /opt/dmdbms/bin./dimp USERIDSYSDBA/SYSDBA001 FILE/opt/dmdbms/ZFJG_LJ20240407.dmp SCHEMASZFJG_LJUSERIDSYSD…