本文主要是介绍《QT实用小工具·三十二》九宫格炫酷主界面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、概述
源码放在文章末尾
项目实现了九宫格炫酷主界面,下面是项目demo演示:
项目部分代码如下:
#pragma execution_character_set("utf-8")#include "frmmain.h"
#include "ui_frmmain.h"frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain)
{ui->setupUi(this);this->initForm();
}frmMain::~frmMain()
{delete ui;
}void frmMain::initForm()
{this->setWindowTitle("九宫格主界面");bg = "main2.jpg";QList<QToolButton *> btns = this->findChildren<QToolButton *>();foreach (QToolButton *btn, btns) {connect(btn, SIGNAL(clicked()), this, SLOT(buttonClick()));}
}void frmMain::buttonClick()
{QToolButton *btn = (QToolButton *)sender();QString objName = btn->objectName();if (objName == "btnCOMTool") {if (bg == "main1.jpg") {bg = "main2.jpg";} else if (bg == "main2.jpg") {bg = "main3.jpg";} else if (bg == "main3.jpg") {bg = "main4.jpg";} else if (bg == "main4.jpg") {bg = "main5.jpg";} else if (bg == "main5.jpg") {bg = "main1.jpg";}QString qss = QString("QWidget#frm{background-image: url(:/image/%1);}").arg(bg);qss += "QToolButton{color:#E7ECF0;background-color:rgba(0,0,0,0);border-style:none;}";this->setStyleSheet(qss);} else if (objName == "btnAddressTool") {} else if (objName == "btnTCPTool") {this->close();} else if (objName == "btnCOMTCPTool") {} else if (objName == "btnDefence") {} else if (objName == "btnHostTool") {} else if (objName == "btnLinkTool") {} else if (objName == "btnMaiChongTool") {} else if (objName == "btnPlot") {} else if (objName == "btnZhangLi4Tool") {} else if (objName == "btnZhangLi5Tool") {} else if (objName == "btnZhangLiTool") {}
}
源码下载
这篇关于《QT实用小工具·三十二》九宫格炫酷主界面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!