添加高dpi支持

qt6
zcy 2020-12-04 21:12:58 +08:00
parent c772cb2c71
commit eb0505738b
13 changed files with 61 additions and 42 deletions

54
Qss.cpp
View File

@ -53,25 +53,27 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
m_titlebarTitle = new QLabel(this);//
m_titlebarTitle->setObjectName("titlebartitle");//css
m_titlebarTitle->setStyleSheet("color: white;margin-left:4px;font-size:15px;");
m_titlebarTitle->setStyleSheet("color: white;");
m_titlebarTitle->setFont(QFont("微软雅黑", 16));
QHBoxLayout* hBox = new QHBoxLayout(this);
hBox->setMargin(0);
hBox->addWidget(m_iconBtn);
hBox->addStretch(20);
hBox->addWidget(m_titlebarTitle);
hBox->addStretch(1);
hBox->addStretch(19);
hBox->addWidget(m_minBtn);
hBox->addWidget(m_restoreBtn);
m_restoreBtn->setVisible(m_maxOrRestore);//
m_restoreBtn->setVisible(m_maxOrRestore);
hBox->addWidget(m_maxBtn);
hBox->addWidget(m_closeBtn);
hBox->setSpacing(0);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);//
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
connect(m_closeBtn, SIGNAL(clicked()), parent, SLOT(close()));//
connect(m_closeBtn, SIGNAL(clicked()), parent, SLOT(close()));
connect(m_minBtn, SIGNAL(clicked()), parent, SLOT(showMinimized()));
connect(m_maxBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));//
connect(m_maxBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
m_iconBtn->installEventFilter(this);//m_iconLab
@ -83,6 +85,7 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
Qt::MSWindowsFixedSizeDialogHint);
this->setGeometry(parent->geometry().x(),parent->geometry().y(),0,0);
m_rcNormal = parentWidget()->geometry();
this->setStyleSheet("font-size:30px;");
}
QssTtitleBar::~QssTtitleBar()
@ -145,7 +148,6 @@ void QssTtitleBar::mouseMoveEvent( QMouseEvent * ev )
QPoint globalPt = ev->globalPos();
QPoint movePt = globalPt - m_pressedPos;//FrameglobalPos
parentWidget()->move(movePt);//globalPos
qDebug()<<parentWidget()->geometry()<<movePt;
return ;
}
@ -182,7 +184,6 @@ bool QssTtitleBar::eventFilter( QObject * obj, QEvent * ev )
void QssMainWindow::OnMaxOrRestore(bool max)
{
qDebug()<<"sended";
if (max)
{
setMinimumSize(0, 0);
@ -225,7 +226,6 @@ void QssMainWindow::OnMaxOrRestore(bool max)
QDesktopWidget desktop;
QRect rc = desktop.availableGeometry(-1);
qDebug()<<"parent is"<<parentWidget()->objectName()<<this->objectName();
parentWidget()->setGeometry(rc);
rc.setRight(rc.right() - 50);
@ -236,6 +236,7 @@ void QssMainWindow::OnMaxOrRestore(bool max)
QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* = 0*/,float scale)
: QMainWindow(parent, flags),
ICallDPIChanged(),
m_mousePressedInBoundy(false),
m_bLeftPress(false)
{
@ -259,7 +260,6 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
vbox->setMargin(2);
vbox->setSpacing(0);
vbox->addWidget(this);
qDebug()<<this->children()[0]->objectName();
installEventFilter(this);
mFrameRect = m_frame->geometry();
@ -362,6 +362,12 @@ int QssMainWindow::CalCursorPos(QPoint pt, int colPos)
return ((pt.y() < FRAMESHAPE ? 10 : ((pt.y() > this->height() - FRAMESHAPE) ? 30 : 20)) + colPos);
}
void QssMainWindow::SetTitleHeight(uint32_t height)
{
this->m_titleBar->setFixedHeight(height);
}
int QssMainWindow::CalCursorCol(QPoint pt)
{
return (pt.x() < FRAMESHAPE ? 1 : ((pt.x() > this->width() - FRAMESHAPE) ? 3 : 2));
@ -477,13 +483,11 @@ void QssMainWindow::onMousePressEvent( QMouseEvent * ev )
}
}
m_rtPreGeometry = mFrameRect;
qDebug("frame geometry is %d %d %d %d",mFrameRect.x(),mFrameRect.y(),
mFrameRect.width(),mFrameRect.height());
}
void QssMainWindow::onMouseReleaseEvent( QMouseEvent * ev )
{
qDebug("mouse release");
m_bLeftPress = false;
m_mousePressedInBoundy = false;
}
@ -508,7 +512,6 @@ bool QssMainWindow::eventFilter( QObject * obj, QEvent * ev )
}
else if (ev->type() == QEvent::MouseButtonPress)
{
qDebug()<<"mouse button pressed\r\n";
QMouseEvent * mouseEv = dynamic_cast<QMouseEvent *>(ev);
if (ev)
{
@ -555,7 +558,6 @@ bool QssMainWindow::eventFilter( QObject * obj, QEvent * ev )
m_frame->setCursor(Qt::ArrowCursor);
}
if(ev->type() == QEvent::Resize){
qDebug()<<"resize ";
}
}
else if (obj == this)
@ -584,7 +586,6 @@ bool QssMainWindow::eventFilter( QObject * obj, QEvent * ev )
}
}
if(QEvent::Resize == ev->type()){
qDebug()<<this->parentWidget()->geometry();
}
}
@ -596,6 +597,21 @@ bool QssMainWindow::eventFilter( QObject * obj, QEvent * ev )
return QMainWindow::eventFilter(obj, ev);
}
void QssMainWindow::ScaleChanged(float scale)
{
}
WId QssMainWindow::GetWID() const
{
}
void QssMainWindow::SetScale(float scale)
{
}
QssDialog::QssDialog(QWidget *parent)
: QDialog(0),
m_mousePressedInBorder(false),
@ -697,8 +713,7 @@ void QssDialog::setWindowIcon( QIcon icon )
void QssDialog::onMouseMoveEvent( QMouseEvent * ev )
{
if (m_mousePressedInBorder)
{
if (m_mousePressedInBorder) {
int x = ev->globalPos().x();
int y = ev->globalPos().y();
@ -728,8 +743,7 @@ void QssDialog::onMouseMoveEvent( QMouseEvent * ev )
mFrameRect = rc;
m_pos = ev->globalPos();
}
else
{
else {
int x = ev->x() + QSSDIALOG_SHADOW_WIDTH - 2;
int y = ev->y() + QSSDIALOG_SHADOW_WIDTH - 2;

10
Qss.h
View File

@ -64,7 +64,8 @@ public:
enum QTitleBar_Type
{
QTitleBar_Type_MainWindow = QTitleBar_Button_Min | QTitleBar_Button_Max | QTitleBar_Button_Restore | QTitleBar_Button_Close,
QTitleBar_Type_MainWindow = QTitleBar_Button_Min |
QTitleBar_Button_Max |QTitleBar_Button_Restore | QTitleBar_Button_Close,
QTitleBar_Type_Dialog = QTitleBar_Button_Close,
QTitleBar_Type_MessageBox = QTitleBar_Button_Close
};
@ -111,7 +112,7 @@ private:
QTitleBar_Type m_type;
};
class QssMainWindow : public QMainWindow
class QssMainWindow : public QMainWindow,ICallDPIChanged
{
Q_OBJECT
@ -130,7 +131,7 @@ public:
void setWindowTitle( QString title );
void setWindowIcon( QIcon icon );
int CalCursorPos(QPoint pt, int colPos);
void SetTitleHeight(uint32_t height);
inline QssTtitleBar* titleBar(){return m_titleBar;}
inline QFrame* frame(){return m_frame;}
int CalCursorCol(QPoint pt); //计算鼠标X的位置
@ -149,6 +150,9 @@ protected:
QssTtitleBar* m_titleBar;
void showEvent(QShowEvent *ev);
virtual void ScaleChanged(float scale) ;
virtual WId GetWID() const;
virtual void SetScale(float scale) ;
private:
QRect m_rcValid;//桌面最大可用尺寸

View File

@ -68,12 +68,9 @@ QPushButton#btn_process:enabled:pressed{
}
QWidget {
font-size: 15px;
font-size: 20px;
}
QWidget:QLabel{
font-size: 15px;
}
QWidget#customWidget {
background: rgb(173, 202, 232);
}
@ -108,7 +105,6 @@ QWidget#titlebar{
background: rgb(7,71,166);
border: 0px;
margin: 0px;
}
QWidget#remoteWidget {
border-top-right-radius: 10px;
@ -171,21 +167,22 @@ QMenu {
}
QssMessageBox#messagebox{
background: rgb(0, 0, 250);
}
QPushButton#titlebaricon{
image: url(:/qss/icon/logo.png);
/* image: url(:/qss/icon/logo.png);*/
background: rgb(7,71,166);
width: 25px;
height:25px;
width: 30px;
height:30px;
}
QLable#titlebartitle{
QLable#titlebartitle1{
font-family:"微软雅黑";
color: white;
font-family: Arial;
}
QPushButton#titlebartitle{
font: 12px sans-serif;
font-size: 16px;
}
QPushButton#titlebarclosebtn{
image: url(":/qss/icon/btn_close_down.svg");
background: rgb(7,71,166);
@ -817,7 +814,7 @@ QLabel#seperateLabel {
QLabel#radiusBlueLabel {
border-radius: 15px;
color: white;
font-size: 15px;
font-size: 18px;
background: rgb(0, 78, 161);
}
@ -889,7 +886,7 @@ QPushButton{
border: none;
width: 75px;
height: 25px;
font-size: 15px;
font-size: 18px;
color: black;
}
QPushButton:enabled {

1
icon/1-最大化.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1580369534607" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3686" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M444.3 539.9L202 782.2 199.8 563c0-16.5-13.5-30-30-30s-30 13.5-30 30l2.2 285.1c0 8.8 3.8 16.7 9.8 22.2 5.5 6 13.4 9.8 22.2 9.8h295.6c16.5 0 30-13.5 30-30s-13.5-30-30-30H248.9l237.8-237.8c11.7-11.7 11.7-30.8 0-42.4-11.6-11.6-30.7-11.6-42.4 0zM578.1 488l242.3-242.3 2.2 219.2c0 16.5 13.5 30 30 30s30-13.5 30-30l-2.2-285.1c0-8.8-3.8-16.7-9.8-22.2-5.5-6-13.4-9.8-22.2-9.8H552.8c-16.5 0-30 13.5-30 30s13.5 30 30 30h220.7L535.7 445.6c-11.7 11.7-11.7 30.8 0 42.4 11.7 11.7 30.8 11.7 42.4 0z" p-id="3687" fill="#ffffff"></path></svg>

After

Width:  |  Height:  |  Size: 902 B

1
icon/array.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1606632646518" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8424" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M128 213.333333C128 166.4 166.4 128 213.333333 128L810.666667 128C857.6 128 896 166.4 896 213.333333L896 810.666667C896 857.6 857.6 896 810.666667 896L213.333333 896C165.973333 896 128 857.6 128 810.666667L128 213.333333M256 256 256 768 426.666667 768 426.666667 682.666667 341.333333 682.666667 341.333333 341.333333 426.666667 341.333333 426.666667 256 256 256M682.666667 682.666667 597.333333 682.666667 597.333333 768 768 768 768 256 597.333333 256 597.333333 341.333333 682.666667 341.333333 682.666667 682.666667Z" p-id="8425"></path></svg>

After

Width:  |  Height:  |  Size: 923 B

1
icon/boolean.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1606630428606" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7152" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M960 1024H64a64 64 0 0 1-64-64V64a64 64 0 0 1 64-64h896a64 64 0 0 1 64 64v896a64 64 0 0 1-64 64zM896 192a64 64 0 0 0-64-64H192a64 64 0 0 0-64 64v640a64 64 0 0 0 64 64h640a64 64 0 0 0 64-64V192z m-512 512L192 448h128l126.464 168.576L704 256h128l-320 448H384z" p-id="7153"></path></svg>

After

Width:  |  Height:  |  Size: 661 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

BIN
icon/int.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@ -1 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1580818365458" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6520" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><defs><style type="text/css"></style></defs><path d="M332.799002 686.081014m-332.799002 0a332.799002 332.799002 0 1 0 665.598003 0 332.799002 332.799002 0 1 0-665.598003 0Z" fill="#D3EFDE" p-id="6521"></path><path d="M883.19735 1024h-639.99808A141.055577 141.055577 0 0 1 102.399693 883.200422v-742.397772A141.055577 141.055577 0 0 1 243.19927 0.003072h516.350451a89.087733 89.087733 0 0 1 63.231811 25.599923l189.695431 189.695431A38.399885 38.399885 0 0 1 1023.996928 243.202342v639.99808a141.055577 141.055577 0 0 1-140.799578 140.799578zM243.19927 76.802842A63.999808 63.999808 0 0 0 179.199462 140.80265v742.397772A63.999808 63.999808 0 0 0 243.19927 947.20023h639.99808a63.999808 63.999808 0 0 0 63.999808-63.999808V259.074295l-179.199462-179.199463a12.799962 12.799962 0 0 0-8.447975-3.07199z" fill="#434260" p-id="6522"></path><path d="M332.799002 399.105875h35.583893v226.047322H332.799002zM428.798714 399.105875h36.60789l75.007775 132.607602 22.783931 47.871856h1.535996c-1.791995-23.29593-4.607986-51.199846-4.607986-75.263774v-105.215684h33.791898v226.047322h-35.839892l-75.007775-133.3756-22.271933-47.359858h-1.535996c1.791995 23.29593 4.607986 49.407852 4.607986 73.983778v106.49568h-35.071894zM700.413899 428.801786h-66.303801v-29.695911h168.447494v29.695911h-66.5598v196.095411h-35.583893z" fill="#434260" p-id="6523"></path></svg>
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1606629528256" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="6317" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M332.799002 686.081014m-332.799002 0a332.799002 332.799002 0 1 0 665.598003 0 332.799002 332.799002 0 1 0-665.598003 0Z" fill="#D3EFDE" p-id="6318"></path><path d="M883.19735 1024h-639.99808A141.055577 141.055577 0 0 1 102.399693 883.200422v-742.397772A141.055577 141.055577 0 0 1 243.19927 0.003072h516.350451a89.087733 89.087733 0 0 1 63.231811 25.599923l189.695431 189.695431A38.399885 38.399885 0 0 1 1023.996928 243.202342v639.99808a141.055577 141.055577 0 0 1-140.799578 140.799578zM243.19927 76.802842A63.999808 63.999808 0 0 0 179.199462 140.80265v742.397772A63.999808 63.999808 0 0 0 243.19927 947.20023h639.99808a63.999808 63.999808 0 0 0 63.999808-63.999808V259.074295l-179.199462-179.199463a12.799962 12.799962 0 0 0-8.447975-3.07199z" fill="#434260" p-id="6319"></path><path d="M332.799002 399.105875h35.583893v226.047322H332.799002zM428.798714 399.105875h36.60789l75.007775 132.607602 22.783931 47.871856h1.535996c-1.791995-23.29593-4.607986-51.199846-4.607986-75.263774v-105.215684h33.791898v226.047322h-35.839892l-75.007775-133.3756-22.271933-47.359858h-1.535996c1.791995 23.29593 4.607986 49.407852 4.607986 73.983778v106.49568h-35.071894zM700.413899 428.801786h-66.303801v-29.695911h168.447494v29.695911h-66.5598v196.095411h-35.583893z" fill="#434260" p-id="6320"></path></svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1580818412833" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7509" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32"><defs><style type="text/css"></style></defs><path d="M341.333333 725.333333 42.666667 725.333333c-25.6 0-42.666667-17.066667-42.666667-42.666667L0 42.666667c0-25.6 17.066667-42.666667 42.666667-42.666667l640 0c25.6 0 42.666667 17.066667 42.666667 42.666667l0 298.666667c0 25.6-17.066667 42.666667-42.666667 42.666667s-42.666667-17.066667-42.666667-42.666667L640 85.333333 85.333333 85.333333l0 554.666667 256 0c25.6 0 42.666667 17.066667 42.666667 42.666667S366.933333 725.333333 341.333333 725.333333z" p-id="7510"></path><path d="M981.333333 1024 341.333333 1024c-25.6 0-42.666667-17.066667-42.666667-42.666667L298.666667 341.333333c0-25.6 17.066667-42.666667 42.666667-42.666667l640 0c25.6 0 42.666667 17.066667 42.666667 42.666667l0 640C1024 1006.933333 1006.933333 1024 981.333333 1024zM384 938.666667l554.666667 0L938.666667 384 384 384 384 938.666667z" p-id="7511"></path></svg>
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1606632592168" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7960" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M341.333333 725.333333 42.666667 725.333333c-25.6 0-42.666667-17.066667-42.666667-42.666667L0 42.666667c0-25.6 17.066667-42.666667 42.666667-42.666667l640 0c25.6 0 42.666667 17.066667 42.666667 42.666667l0 298.666667c0 25.6-17.066667 42.666667-42.666667 42.666667s-42.666667-17.066667-42.666667-42.666667L640 85.333333 85.333333 85.333333l0 554.666667 256 0c25.6 0 42.666667 17.066667 42.666667 42.666667S366.933333 725.333333 341.333333 725.333333z" p-id="7961"></path><path d="M981.333333 1024 341.333333 1024c-25.6 0-42.666667-17.066667-42.666667-42.666667L298.666667 341.333333c0-25.6 17.066667-42.666667 42.666667-42.666667l640 0c25.6 0 42.666667 17.066667 42.666667 42.666667l0 640C1024 1006.933333 1006.933333 1024 981.333333 1024zM384 938.666667l554.666667 0L938.666667 384 384 384 384 938.666667z" p-id="7962"></path></svg>

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

1
icon/关闭.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1580369499637" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2832" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M503.466667 467.285333l319.829333-319.829333a25.6 25.6 0 1 1 36.181333 36.181333l-319.829333 319.829334 319.829333 319.829333a25.6 25.6 0 1 1-36.181333 36.181333l-319.829333-319.829333-319.829334 319.829333a25.6 25.6 0 1 1-36.181333-36.181333l319.829333-319.829333-319.829333-319.829334a25.6 25.6 0 1 1 36.181333-36.181333l319.829334 319.829333z" p-id="2833" fill="#ffffff"></path></svg>

After

Width:  |  Height:  |  Size: 764 B

1
icon/最小化.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1580369518247" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3279" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M98.23 451.003l829.685-1.992 0.154 64-829.685 1.992z" fill="#ffffff" p-id="3280"></path></svg>

After

Width:  |  Height:  |  Size: 471 B

View File

@ -41,7 +41,6 @@
<file>icon/logo.png</file>
<file>icon/key.svg</file>
<file>icon/action_config.png</file>
<file>icon/code-array.svg</file>
<file>icon/int.svg</file>
<file>icon/objects.svg</file>
<file>icon/string.svg</file>