龙空技术网

Qt编写小清新风格界面

Qt自定义控件 19415

前言:

今天大家对“html导航栏怎么做好看”大体比较注重,各位老铁们都需要剖析一些“html导航栏怎么做好看”的相关知识。那么小编在网络上收集了一些关于“html导航栏怎么做好看””的相关资讯,希望小伙伴们能喜欢,我们快快来学习一下吧!

给一个朋友做的界面,左侧有导航,左侧底部有运行+暂停+停止按钮,右侧有可伸缩面板,面板之间可以拉伸调节高度,左右两侧可以拉伸调节高度,所有的宽高和位置都保存在配置文件,下次重启立即应用,无边框标题栏,异形菜单栏,在自定义标题栏和自定义左侧导航栏中间。底部可以动态添加设备面板,自动放入面板容器。

用Qt做这种界面还是非常便捷的,整体的大部分可以直接用QSS控制,QSS是类似于CSS的颜色样式控制,可以做到动态换肤,少部分不能满足的可以直接用qpainter这个武器来绘制,这样两者结合无敌。

部分代码

#pragma execution_character_set("utf-8")#include "frmmain.h"#include "ui_frmmain.h"#include "mainwindow.h"#include "quiwidget.h"#include "appinit.h"frmMain::frmMain(QWidget *parent) : QWidget(parent), ui(new Ui::frmMain){ ui->setupUi(this); this->initForm(); this->initLocation(); this->initNav1(); this->initNav2(); this->changeBtnStyle(); ui->tbtn1->click();}frmMain::~frmMain(){ delete ui;}bool frmMain::eventFilter(QObject *watched, QEvent *event){ if (watched == ui->widgetTop) { if (event->type() == QEvent::MouseButtonDblClick) { on_btnMenu_Max_clicked(); } } return QWidget::eventFilter(watched, event);}void frmMain::initForm(){ //将带菜单的窗体作为子窗体加入到界面中 MainWindow *mainWindow = new MainWindow; ui->widgetMain->layout()->addWidget(mainWindow); //设置无边框窗体 ui->widget->setProperty("form", true); this->setProperty("canMove", true); this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); this->setWindowTitle("数字化医疗系统"); ui->labTitle->setText(this->windowTitle()); ui->widgetTop->installEventFilter(this); ui->widgetNav1->setProperty("flag", "left"); ui->widgetNav2->setProperty("flag", "bottom"); ui->widgetLeft->setFixedWidth(80); ui->widgetNav2->setFixedHeight(220); ui->labLogo->setFixedHeight(55); //设置图形字体,logo可以换成图片#if 0 QPixmap pix(":/image/logo.png"); pix = pix.scaled(ui->labLogo->size() - QSize(10, 10), Qt::KeepAspectRatio, Qt::SmoothTransformation); ui->labLogo->setPixmap(pix);#else IconHelper::Instance()->setIcon(ui->labLogo, QChar(0xf1b3), 35);#endif IconHelper::Instance()->setIcon(ui->btnMenu_Min, QChar(0xf068)); IconHelper::Instance()->setIcon(ui->btnMenu_Max, QChar(0xf067)); IconHelper::Instance()->setIcon(ui->btnMenu_Close, QChar(0xf00d)); ui->line1->setFixedHeight(1); ui->line2->setFixedHeight(1); ui->line3->setFixedWidth(1); //绑定样式改变信号 connect(AppInit::Instance(), SIGNAL(changeStyle(QString)), this, SLOT(changeBtnStyle())); //如果默认窗体大小则设置窗体居中大小适中 if (App::FormGeometry == QRect(0, 0, 0, 0)) { int width = 1000; int height = 700; int x = (QUIHelper::deskWidth() - width) / 2; int y = (QUIHelper::deskHeight() - height) / 2; App::FormGeometry = QRect(x, y, width, height); } //如果最后是最大化则启动后直接应用最大化 location = App::FormGeometry;}void frmMain::initLocation(){ if (App::FormMax) { location = this->geometry(); this->setGeometry(qApp->desktop()->availableGeometry()); } else { this->setGeometry(location); } this->setProperty("canMove", !App::FormMax); ui->btnMenu_Max->setToolTip(App::FormMax ? "还原" : "最大化"); IconHelper::Instance()->setIcon(ui->btnMenu_Max, App::FormMax ? QUIConfig::IconMax : QUIConfig::IconNormal);}void frmMain::initNav1(){ pixChar1 << 0xf0e8 << 0xf080 << 0xf085; btns1 << ui->tbtn1 << ui->tbtn2 << ui->tbtn3; int count = btns1.count(); for (int i = 0; i < count; i++) { QToolButton *btn = btns1.at(i); btn->setCheckable(true); btn->setFixedHeight(60); btn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClicked1())); }}void frmMain::initNav2(){ pixChar2 << 0xf07c << 0xf04b << 0xf04c << 0xf04d; btns2 << ui->btnFile << ui->btnRun << ui->btnPause << ui->btnStop; int count = btns2.count(); for (int i = 0; i < count; i++) { QToolButton *btn = btns2.at(i); btn->setToolButtonStyle(Qt::ToolButtonIconOnly); connect(btn, SIGNAL(clicked(bool)), this, SLOT(buttonClicked2())); }}void frmMain::buttonClicked1(){ QToolButton *b = (QToolButton *)sender(); //ui->stackedWidget->setCurrentIndex(btns.indexOf(b)); int count = btns1.count(); for (int i = 0; i < count; i++) { QToolButton *btn = btns1.at(i); bool check = (btn == b); btn->setChecked(check); btn->setIcon(QIcon(IconHelper::Instance()->getPixmap(btn, !check))); }}void frmMain::buttonClicked2(){ QToolButton *b = (QToolButton *)sender(); //ui->stackedWidget->setCurrentIndex(btns.indexOf(b)); int count = btns1.count(); for (int i = 0; i < count; i++) { QToolButton *btn = btns1.at(i); bool check = (btn == b); btn->setIcon(QIcon(IconHelper::Instance()->getPixmap(btn, !check))); }}void frmMain::changeBtnStyle(){ int iconSize = 25; int iconWidth = 30; int iconHeight = 30; int borderWidth = 3; QString borderColor = QUIConfig::HighColor; QString normalBgColor = QUIConfig::NormalColorStart; QString darkBgColor = QUIConfig::PanelColor; QString normalTextColor = QUIConfig::TextColor; QString darkTextColor = QUIConfig::TextColor; IconHelper::Instance()->removeStyle(btns1); IconHelper::Instance()->setStyle(ui->widgetNav1, btns1, pixChar1, iconSize, iconWidth, iconHeight, "left", borderWidth, borderColor, normalBgColor, darkBgColor, normalTextColor, darkTextColor); //采用三态设置方法 IconHelper::StyleColor styleColor; styleColor.iconSize = 20; styleColor.iconWidth = 22; styleColor.iconHeight = 22; styleColor.borderWidth = 0; styleColor.type = "bottom"; styleColor.normalBgColor = QUIConfig::NormalColorStart; styleColor.normalTextColor = QUIConfig::TextColor; styleColor.hoverBgColor = QUIConfig::PanelColor; styleColor.hoverTextColor = QUIConfig::TextColor; styleColor.pressedBgColor = QUIConfig::DarkColorStart; styleColor.pressedTextColor = QUIConfig::TextColor; styleColor.checkedBgColor = QUIConfig::DarkColorStart; styleColor.checkedTextColor = QUIConfig::TextColor; IconHelper::Instance()->removeStyle(btns2); IconHelper::Instance()->setStyle(ui->widgetNav2, btns2, pixChar2, styleColor);}void frmMain::on_btnMenu_Min_clicked(){ showMinimized();}void frmMain::on_btnMenu_Max_clicked(){ App::FormMax = !App::FormMax; App::writeConfig(); this->initLocation();}void frmMain::on_btnMenu_Close_clicked(){ //退出前保存最后的窗体坐标+宽高 if (!App::FormMax) { App::FormGeometry = this->geometry(); App::writeConfig(); } close();}

标签: #html导航栏怎么做好看