拆分框架的css

qt6
zcy 2020-12-14 23:48:37 +08:00
parent e4ba3226ed
commit 23a6da5d3f
5 changed files with 111 additions and 21 deletions

46
Qss.cpp
View File

@ -34,20 +34,19 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
m_type(type), m_type(type),
m_Main(nullptr) m_Main(nullptr)
{ {
setObjectName("titlebar"); setObjectName("qssTitleBar");
m_closeBtn = new QPushButton(this);
m_closeBtn = new QPushButton(this);// m_closeBtn->setObjectName("titlebarclosebtn");
m_closeBtn->setObjectName("titlebarclosebtn");//css
m_closeBtn->setToolTip(QString::fromLocal8Bit("")); m_closeBtn->setToolTip(QString::fromLocal8Bit(""));
m_closeBtn->setVisible(m_type & QTitleBar_Button_Close); m_closeBtn->setVisible(m_type & QTitleBar_Button_Close);
m_minBtn = new QPushButton(this); m_minBtn = new QPushButton(this);
m_minBtn->setObjectName("titlebarminbtn");//css m_minBtn->setObjectName("titlebarminbtn");
m_minBtn->setToolTip(QString::fromLocal8Bit("最大化")); m_minBtn->setToolTip(QString::fromLocal8Bit("最大化"));
m_minBtn->setVisible(m_type & QTitleBar_Button_Min); m_minBtn->setVisible(m_type & QTitleBar_Button_Min);
m_restoreBtn = new QPushButton(this);// m_restoreBtn = new QPushButton(this);//
m_restoreBtn->setObjectName("titlebarrestorebtn");//css m_restoreBtn->setObjectName("titlebarrestorebtn");
m_restoreBtn->setToolTip(QString::fromLocal8Bit("")); m_restoreBtn->setToolTip(QString::fromLocal8Bit(""));
m_restoreBtn->setVisible(m_type & QTitleBar_Button_Restore); m_restoreBtn->setVisible(m_type & QTitleBar_Button_Restore);
@ -56,13 +55,11 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
m_maxBtn->setToolTip(QString::fromLocal8Bit("")); m_maxBtn->setToolTip(QString::fromLocal8Bit(""));
m_maxBtn->setVisible(m_type & QTitleBar_Button_Max); m_maxBtn->setVisible(m_type & QTitleBar_Button_Max);
m_iconBtn = new QPushButton(this);// m_iconBtn = new QPushButton(this);
m_iconBtn->setObjectName("titlebaricon");//css m_iconBtn->setObjectName("titlebaricon");
m_titlebarTitle = new QLabel(this);// m_titlebarTitle = new QLabel(this);
m_titlebarTitle->setObjectName("titlebartitle");//css m_titlebarTitle->setObjectName("titlebartitle");
m_titlebarTitle->setStyleSheet("color: white;");
m_titlebarTitle->setFont(QFont("微软雅黑", 16));
QHBoxLayout* hBox = new QHBoxLayout(this); QHBoxLayout* hBox = new QHBoxLayout(this);
hBox->setMargin(0); hBox->setMargin(0);
@ -85,7 +82,7 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore())); connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
m_iconBtn->installEventFilter(this);//m_iconLab m_iconBtn->installEventFilter(this);//m_iconLab
installEventFilter(this);// installEventFilter(this);
m_rcValid = QApplication::desktop()->availableGeometry(); m_rcValid = QApplication::desktop()->availableGeometry();
this->setFixedHeight(37); this->setFixedHeight(37);
@ -93,7 +90,16 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
Qt::MSWindowsFixedSizeDialogHint); Qt::MSWindowsFixedSizeDialogHint);
this->setGeometry(parent->geometry().x(),parent->geometry().y(),0,0); this->setGeometry(parent->geometry().x(),parent->geometry().y(),0,0);
m_rcNormal = parentWidget()->geometry(); m_rcNormal = parentWidget()->geometry();
this->setStyleSheet("font-size:30px;");
QFile file(":/qss/css/QssTitleBar.css");
if (!file.open(QIODevice::ReadOnly)){
qDebug()<<"error bar";
exit(0);
}
QTextStream in(&file);
QString css = in.readAll();
this->setStyleSheet(css);
} }
QssTtitleBar::~QssTtitleBar() QssTtitleBar::~QssTtitleBar()
@ -274,7 +280,17 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
m_rcNormal = m_frame->geometry(); m_rcNormal = m_frame->geometry();
m_rcNormalCentral = this->geometry(); m_rcNormalCentral = this->geometry();
connect(this->titleBar(),SIGNAL( OnMaxOrRestore(bool )),this,SLOT(OnMaxOrRestore(bool))); connect(this->titleBar(),SIGNAL( OnMaxOrRestore(bool )),this,SLOT(OnMaxOrRestore(bool)));
QFile file(":/qss/css/QssMainWindow.css");
if (!file.open(QIODevice::ReadOnly)){
qDebug()<<"error bar";
exit(0);
}
QTextStream in(&file);
QString css = in.readAll();
//this->setStyleSheet(css);
return;
} }
QssMainWindow::~QssMainWindow() QssMainWindow::~QssMainWindow()
@ -1376,7 +1392,7 @@ QssDockWidget::QssDockWidget(QWidget *parent)
m_frame = new QFrame(parent); m_frame = new QFrame(parent);
m_frame->setObjectName("dialog");//css m_frame->setObjectName("dialog");//css
m_frame->setAttribute(Qt::WA_TranslucentBackground);/** padding css boder<65><72>*/ m_frame->setAttribute(Qt::WA_TranslucentBackground);/** padding css boder<65><72>*/
m_frame->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint m_frame->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
m_frame->setMouseTracking(true); m_frame->setMouseTracking(true);
m_frame->installEventFilter(this); m_frame->installEventFilter(this);

10
css/QssMainWindow.css Normal file
View File

@ -0,0 +1,10 @@
QMainWindow{
border: none;
background: rgb(245, 252, 252);
font-family:"微软雅黑";
font-style: normal;
}

61
css/QssTitleBar.css Normal file
View File

@ -0,0 +1,61 @@
QWidget#qssTitleBar{
color: white;
background: rgb(7,71,166);
border: 0px;
margin: 0px;
}
QWidget#qssTitleBar > QPushButton#titlebaricon{
background: rgb(7,71,166);
width: 30px;
height:30px;
}
QWidget#qssTitleBar > QLable#titlebartitle{
font-family:"微软雅黑";
color: white;
font-size: 30px;
}
QWidget#qssTitleBar>QPushButton#titlebarclosebtn{
image: url(":/qss/icon/btn_close_down.svg");
background: rgb(7,71,166);
width: 40px;
height:30px;
margin-left: 1px;
}
QWidget#qssTitleBar >QPushButton#titlebarmaxbtn{
background: rgb(7,71,166);
width: 40px;
height:30px;
margin-left: 1px;
image: url(":/qss/icon/btn_max_normal.svg");
}
QWidget#qssTitleBar >QPushButton#titlebarclosebtn:enabled:hover{
background: red;
}
QWidget#qssTitleBar >QPushButton#titlebarminbtn{
image: url(":/qss/icon/btn_mini_down.svg");
background: rgb(7,71,166);
width: 40px;
height:30px;
margin-left: 1px;
}
QWidget#qssTitleBar >QPushButton#titlebarminbtn:enabled:hover{
background: rgb(187, 212, 238);
}
QWidget#qssTitleBar >QPushButton#titlebarrestorebtn{
image: url(":/qss/icon/btn_max_normal.svg");
background: rgb(187, 212, 238);
width: 40px;
height:30px;
margin-left: 1px;
}
QWidget#qssTitleBar >QPushButton#titlebarrestorebtn:enabled:hover{
background: rgb(187, 212, 238);
}
QWidget#qssTitleBar >QPushButton#btn_serial:!enabled {
background: rgb(180, 180, 180);
color: white;
}
QWidget#qssTitleBar >QPushButton#titlebarmaxbtn:enabled:hover{
background: rgb(100, 160, 220);
}

View File

@ -100,12 +100,7 @@ QFrame#window{
background: rgba(244,245,247,100); background: rgba(244,245,247,100);
} }
QWidget#titlebar{
color: white;
background: rgb(7,71,166);
border: 0px;
margin: 0px;
}
QWidget#remoteWidget { QWidget#remoteWidget {
border-top-right-radius: 10px; border-top-right-radius: 10px;
border-bottom-right-radius: 10px; border-bottom-right-radius: 10px;
@ -170,6 +165,12 @@ QMenu {
QssMessageBox#messagebox{ QssMessageBox#messagebox{
background: rgb(0, 0, 250); background: rgb(0, 0, 250);
} }
QWidget#titlebar{
color: white;
background: rgb(7,71,166);
border: 0px;
margin: 0px;
}
QPushButton#titlebaricon{ QPushButton#titlebaricon{
/* image: url(:/qss/icon/logo.png);*/ /* image: url(:/qss/icon/logo.png);*/
background: rgb(7,71,166); background: rgb(7,71,166);

View File

@ -46,5 +46,7 @@
<file>icon/string.svg</file> <file>icon/string.svg</file>
<file>icon/最大化.svg</file> <file>icon/最大化.svg</file>
<file>icon/missing.svg</file> <file>icon/missing.svg</file>
<file>css/QssMainWindow.css</file>
<file>css/QssTitleBar.css</file>
</qresource> </qresource>
</RCC> </RCC>