From 4488d85f9e7326a021ed2bed6811bd20c3c05dba Mon Sep 17 00:00:00 2001 From: tanyulong Date: Tue, 13 Jul 2021 09:50:49 +0800 Subject: [PATCH] window add title icon --- shell/customstyle.cpp | 10 +++++++++- shell/mainwindow.cpp | 44 +++++++++++++++++++++++++------------------ shell/mainwindow.h | 1 + shell/mainwindow.ui | 4 ++-- shell/prescene.cpp | 14 +++++++++++++- shell/prescene.h | 1 + 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/shell/customstyle.cpp b/shell/customstyle.cpp index 0718c2e..82ae674 100755 --- a/shell/customstyle.cpp +++ b/shell/customstyle.cpp @@ -138,7 +138,6 @@ void InternalStyle::drawComplexControl(QStyle::ComplexControl control, const QSt void InternalStyle::polish(QPalette &pal) { QProxyStyle::polish(pal); - pal.setColor(QPalette::Window, pal.base().color()); pal.setColor(QPalette::Inactive, QPalette::Base, pal.base().color()); // pal.setColor(QPalette::Button, pal.alternateBase().color()); } @@ -151,4 +150,13 @@ void InternalStyle::polish(QWidget *widget) pal.setColor(QPalette::Base, pal.alternateBase().color()); widget->setPalette(pal); } + + // 跳过左侧边栏处理 + if (widget && widget->objectName() == "leftsidebarWidget") { + + } else if (widget){ + QPalette paltte = widget->palette(); + paltte.setColor(QPalette::Window, paltte.base().color()); + widget->setPalette(paltte); + } } diff --git a/shell/mainwindow.cpp b/shell/mainwindow.cpp index a85b68a..9a602ef 100755 --- a/shell/mainwindow.cpp +++ b/shell/mainwindow.cpp @@ -368,6 +368,7 @@ void MainWindow::initUI() { //左上角显示字符/返回按钮 backBtn->setVisible(index); titleLabel->setHidden(index); + mTitleIcon->setHidden(index); if (index){ //首页部分组件样式 //中部内容区域 @@ -416,7 +417,8 @@ void MainWindow::initUI() { void MainWindow::initTileBar() { - ui->titleLayout->setContentsMargins(9, 9, 9, 0); + ui->titleLayout->setContentsMargins(4, 4, 4, 0); + ui->titleLayout->setSpacing(0); m_searchWidget = new SearchWidget(this); // char style[100]; // sprintf(style, "SearchWidget{border:0px;background-color:palette(base);border-radius:8px;}", @@ -428,10 +430,9 @@ void MainWindow::initTileBar() { m_queryWid=new QWidget; m_queryWid->setParent(m_searchWidget); m_queryWid->setFocusPolicy(Qt::NoFocus); -// m_queryWid->setStyleSheet("border:0px;background:transparent"); QHBoxLayout* queryWidLayout = new QHBoxLayout; - queryWidLayout->setContentsMargins(4,4,0,0); + queryWidLayout->setContentsMargins(0, 0, 0, 0); queryWidLayout->setAlignment(Qt::AlignJustify); queryWidLayout->setSpacing(0); m_queryWid->setLayout(queryWidLayout); @@ -463,22 +464,29 @@ void MainWindow::initTileBar() { backBtn = new QPushButton(this); minBtn = new QPushButton(this); maxBtn = new QPushButton(this); - closeBtn = new QPushButton(this); + closeBtn = new QPushButton(this); + mTitleIcon = new QLabel(this); titleLabel = new QLabel(tr("UKCC"), this); - backBtn->setFixedSize(32, 32); - minBtn->setFixedSize(32, 32); - maxBtn->setFixedSize(32, 32); // titleLabel->setFixedSize(32, 32); - titleLabel->setFixedHeight(32); - titleLabel->setMinimumWidth(32); + backBtn->setFixedSize(30, 30); + minBtn->setFixedSize(30, 30); + maxBtn->setFixedSize(30, 30); + closeBtn->setFixedSize(30, 30); + mTitleIcon->setFixedSize(30, 30); + + QIcon titleIcon = QIcon::fromTheme("ukui-control-center"); + mTitleIcon->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(24, 24)))); + + titleLabel->setFixedSize(30, 30); titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); m_searchWidget->setMinimumWidth(350); - m_searchWidget->setMinimumHeight(40); + m_searchWidget->setMinimumHeight(35); m_searchWidget->setMaximumWidth(350); - m_searchWidget->setMaximumHeight(40); - - ui->titleLayout->addSpacing(9); + m_searchWidget->setMaximumHeight(35); + + ui->titleLayout->addWidget(mTitleIcon); + ui->titleLayout->addSpacing(8); ui->titleLayout->addWidget(titleLabel); ui->titleLayout->addWidget(backBtn); ui->titleLayout->addStretch(); @@ -621,7 +629,7 @@ void MainWindow::initLeftsideBar(){ connect(hBtn, &QPushButton::clicked, this, [=]{ ui->stackedWidget->setCurrentIndex(0); }); - hBtn->setStyleSheet("QPushButton#homepage{background: palette(button); border: none;}"); + hBtn->setStyleSheet("QPushButton#homepage{background: palette(window); border: none;}"); // hBtn->setStyleSheet("QPushButton#homepage{background: palette(base);}"); ui->leftsidebarVerLayout->addStretch(); ui->leftsidebarVerLayout->addWidget(hBtn); @@ -646,7 +654,7 @@ void MainWindow::initLeftsideBar(){ // button->setStyleSheet("QPushButton::checked{background: palette(button); border: none; border-image: url('://img/primaryleftmenu/checked.png');}" // "QPushButton::!checked{background: palette(button);border: none;}"); button->setStyleSheet("QPushButton::checked{background: palette(base); border-top-left-radius: 6px;border-bottom-left-radius: 6px;}" - "QPushButton::!checked{background: palette(button);border: none;}"); + "QPushButton::!checked{background: palette(window);border: none;}"); connect(button, &QPushButton::clicked, this, [=]{ QPushButton * btn = dynamic_cast(QObject::sender()); @@ -688,9 +696,9 @@ QPushButton * MainWindow::buildLeftsideBtn(QString bname,QString tipName){ iconBtn->setFocusPolicy(Qt::NoFocus); - QString iconHomePageBtnQss = QString("QPushButton{background: palette(button); border: none;}"); + QString iconHomePageBtnQss = QString("QPushButton{background: palette(window); border: none;}"); QString iconBtnQss = QString("QPushButton:checked{background: palette(base); border: none;}" - "QPushButton:!checked{background: palette(button); border: none;}"); + "QPushButton:!checked{background: palette(window); border: none;}"); QString path = QString("://img/primaryleftmenu/%1.svg").arg(iname); QPixmap pix = ImageUtil::loadSvg(path, "default"); //单独设置HomePage按钮样式 @@ -806,7 +814,7 @@ void MainWindow::initStyleSheet() { closeBtn->setFlat(true); closeBtn->installEventFilter(this); - ui->leftsidebarWidget->setStyleSheet("QWidget#leftsidebarWidget{background-color: palette(button);border: none; border-top-left-radius: 6px; border-bottom-left-radius: 6px;}"); + ui->leftsidebarWidget->setStyleSheet("QWidget#leftsidebarWidget{background-color: palette(window);border: none; border-top-left-radius: 6px; border-bottom-left-radius: 6px;}"); // 设置左上角按钮图标 backBtn->setIcon(QIcon("://img/titlebar/back.svg")); diff --git a/shell/mainwindow.h b/shell/mainwindow.h index bb44d7e..d01158f 100755 --- a/shell/mainwindow.h +++ b/shell/mainwindow.h @@ -88,6 +88,7 @@ private: QPushButton * maxBtn; QPushButton * closeBtn; QLabel * titleLabel; + QLabel * mTitleIcon; QTimer * timer; QLabel * logoLabel; QLabel *m_queryIcon; diff --git a/shell/mainwindow.ui b/shell/mainwindow.ui index e1d9b44..1a6cd22 100755 --- a/shell/mainwindow.ui +++ b/shell/mainwindow.ui @@ -66,8 +66,8 @@ 0 - 3 - + 0 + 30 diff --git a/shell/prescene.cpp b/shell/prescene.cpp index 7451c2c..dd04531 100755 --- a/shell/prescene.cpp +++ b/shell/prescene.cpp @@ -15,6 +15,14 @@ PreScene::PreScene(QLabel *label, QSize size, QWidget *parent) : titleLabel(labe m_vlayout = new QVBoxLayout; m_logoLayout = new QHBoxLayout; + mTitleIcon = new QLabel(this); + QIcon titleIcon = QIcon::fromTheme("ukui-control-center"); + mTitleIcon->setPixmap(titleIcon.pixmap(titleIcon.actualSize(QSize(24, 24)))); + + mTitleIcon->setFixedSize(30, 30); + titleLabel->setFixedSize(28, 28); + + titlebar = new QWidget(this); logoLabel = new QLabel(this); logoLabel->setFixedSize(200,200); @@ -23,10 +31,14 @@ PreScene::PreScene(QLabel *label, QSize size, QWidget *parent) : titleLabel(labe m_logoLayout->addWidget(logoLabel); m_hlayout = new QHBoxLayout; - m_hlayout->setContentsMargins(9, 9, 9, 0); + m_hlayout->setContentsMargins(4, 6, 0, 0); + m_hlayout->addWidget(mTitleIcon); m_hlayout->addWidget(titleLabel); + m_hlayout->addStretch(); titlebar->setLayout(m_hlayout); + m_vlayout->setSpacing(0); + m_vlayout->setContentsMargins(0, 0, 0, 0); m_vlayout->addWidget(titlebar); m_vlayout->addLayout(m_logoLayout); m_vlayout->addStretch(); diff --git a/shell/prescene.h b/shell/prescene.h index 49e497a..d02650e 100755 --- a/shell/prescene.h +++ b/shell/prescene.h @@ -23,6 +23,7 @@ private: QVBoxLayout * m_vlayout; QWidget * titlebar; + QLabel * mTitleIcon; QLabel * titleLabel; QLabel * logoLabel; QHBoxLayout * m_logoLayout = nullptr; -- 2.23.0