支持QT6的版本
parent
3c163b6333
commit
1c7d843a04
74
Qss.cpp
74
Qss.cpp
|
@ -6,14 +6,14 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
|
||||||
#include <QtMath>
|
#include <QtMath>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
#include <QParallelAnimationGroup>
|
#include <QParallelAnimationGroup>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QSizePolicy>
|
#include <QSizePolicy>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopServices>
|
||||||
|
#include <QScreen>
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "winuser.h"
|
#include "winuser.h"
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
@ -112,7 +112,7 @@ QssTtitleBar::QssTtitleBar(QWidget *parent ,
|
||||||
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
connect(m_restoreBtn, SIGNAL(clicked()), this, SLOT(onMaxOrRestore()));
|
||||||
|
|
||||||
|
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
|
|
||||||
setWindowFlags(windowFlags()|Qt::MSWindowsFixedSizeDialogHint);
|
setWindowFlags(windowFlags()|Qt::MSWindowsFixedSizeDialogHint);
|
||||||
this->setGeometry(parent->geometry().x(),parent->geometry().y(),0,0);
|
this->setGeometry(parent->geometry().x(),parent->geometry().y(),0,0);
|
||||||
|
@ -178,10 +178,9 @@ void QssTtitleBar::onMaxOrRestore()
|
||||||
}
|
}
|
||||||
void QssTtitleBar::paintEvent(QPaintEvent *)
|
void QssTtitleBar::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QStyleOption opt;
|
QStyleOption opt();
|
||||||
opt.init(this);
|
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
// style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QssTtitleBar::mouseMoveEvent( QMouseEvent * ev )
|
void QssTtitleBar::mouseMoveEvent( QMouseEvent * ev )
|
||||||
|
@ -267,8 +266,7 @@ void QssMainWindow::OnMaxOrRestore(bool max)
|
||||||
this->m_frame->setMinimumSize(0, 0);
|
this->m_frame->setMinimumSize(0, 0);
|
||||||
this->m_frame->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
this->m_frame->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
|
||||||
|
|
||||||
QDesktopWidget desktop;
|
QRect rc = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
QRect rc = desktop.availableGeometry(-1);
|
|
||||||
|
|
||||||
parentWidget()->setGeometry(rc);
|
parentWidget()->setGeometry(rc);
|
||||||
rc.setRight(rc.right() - 50);
|
rc.setRight(rc.right() - 50);
|
||||||
|
@ -316,7 +314,7 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
|
||||||
m_tray_on(false)
|
m_tray_on(false)
|
||||||
{
|
{
|
||||||
QEvent::registerEventType();
|
QEvent::registerEventType();
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
m_frame = new QFrame(parent, flags);
|
m_frame = new QFrame(parent, flags);
|
||||||
m_frame->setObjectName("window");
|
m_frame->setObjectName("window");
|
||||||
|
|
||||||
|
@ -332,7 +330,6 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
|
||||||
m_titleBar->SetMainWindow(this);
|
m_titleBar->SetMainWindow(this);
|
||||||
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
||||||
vbox->addWidget(m_titleBar);
|
vbox->addWidget(m_titleBar);
|
||||||
vbox->setMargin(1);
|
|
||||||
vbox->setSpacing(0);
|
vbox->setSpacing(0);
|
||||||
vbox->addWidget(this);
|
vbox->addWidget(this);
|
||||||
|
|
||||||
|
@ -354,18 +351,7 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
|
||||||
mShadowMask->setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}");
|
mShadowMask->setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}");
|
||||||
mShadowMask->hide();
|
mShadowMask->hide();
|
||||||
|
|
||||||
int screenNum = qApp->desktop()->screenNumber(this);
|
|
||||||
mCurrentScreen = qApp->screens().at(screenNum);
|
|
||||||
if(nullptr != mCurrentScreen){
|
|
||||||
connect(mCurrentScreen,
|
|
||||||
SIGNAL(physicalDotsPerInchChanged(qreal)),
|
|
||||||
this,SLOT(PhisycalDpiChange(qreal)));
|
|
||||||
|
|
||||||
connect(mCurrentScreen,
|
|
||||||
SIGNAL(logicalDotsPerInchChanged(qreal)),
|
|
||||||
this,SLOT(LogicalDpiChange(qreal)));
|
|
||||||
}
|
|
||||||
detectDpi();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,16 +392,7 @@ void QssMainWindow::RangeObject()
|
||||||
rangeObjectList(m_frame,0);
|
rangeObjectList(m_frame,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QssMainWindow::DetectDpiChange()
|
|
||||||
{
|
|
||||||
int screenNum = qApp->desktop()->screenNumber(this);
|
|
||||||
auto currentScreen = qApp->screens().at(screenNum);
|
|
||||||
|
|
||||||
if(currentScreen != mCurrentScreen){
|
|
||||||
qDebug()<<"dpi change,reason screen changed";
|
|
||||||
mCurrentScreen = currentScreen;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void QssMainWindow::ShowMask()
|
void QssMainWindow::ShowMask()
|
||||||
{
|
{
|
||||||
|
@ -883,7 +860,7 @@ bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(QEvent::Resize == ev->type()){
|
if(QEvent::Resize == ev->type()){
|
||||||
QDesktopWidget desktop;
|
|
||||||
}
|
}
|
||||||
if(QEvent::Close == ev->type()){
|
if(QEvent::Close == ev->type()){
|
||||||
qDebug()<<"close";
|
qDebug()<<"close";
|
||||||
|
@ -944,7 +921,7 @@ QssDialog::QssDialog(QWidget *parent)
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
m_mousePressedInBorder(false)
|
m_mousePressedInBorder(false)
|
||||||
{
|
{
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
|
|
||||||
m_frame = new QFrame(parent);
|
m_frame = new QFrame(parent);
|
||||||
m_frame->setObjectName("dialog");//css
|
m_frame->setObjectName("dialog");//css
|
||||||
|
@ -957,7 +934,6 @@ QssDialog::QssDialog(QWidget *parent)
|
||||||
m_titleBar->installEventFilter(this);
|
m_titleBar->installEventFilter(this);
|
||||||
|
|
||||||
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
||||||
vbox->setMargin(0);
|
|
||||||
vbox->setSpacing(0);
|
vbox->setSpacing(0);
|
||||||
vbox->addWidget(m_titleBar);
|
vbox->addWidget(m_titleBar);
|
||||||
vbox->addWidget(this);
|
vbox->addWidget(this);
|
||||||
|
@ -987,6 +963,7 @@ void QssDialog::HideMask()
|
||||||
|
|
||||||
void QssDialog::show()
|
void QssDialog::show()
|
||||||
{
|
{
|
||||||
|
|
||||||
/** resize m_framem_framesizehint */
|
/** resize m_framem_framesizehint */
|
||||||
int offset = (QSSDIALOG_SHADOW_WIDTH + QSSDIALOG_BODER_WIDTH)*2;
|
int offset = (QSSDIALOG_SHADOW_WIDTH + QSSDIALOG_BODER_WIDTH)*2;
|
||||||
m_frame->resize(rect().width() + offset, rect().height() + m_titleBar->rect().height() + offset);
|
m_frame->resize(rect().width() + offset, rect().height() + m_titleBar->rect().height() + offset);
|
||||||
|
@ -997,7 +974,6 @@ void QssDialog::show()
|
||||||
|
|
||||||
void QssDockWidget::paintEvent(QPaintEvent *){
|
void QssDockWidget::paintEvent(QPaintEvent *){
|
||||||
QStyleOption opt;
|
QStyleOption opt;
|
||||||
opt.init(this);
|
|
||||||
QPainter p(this);
|
QPainter p(this);
|
||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
||||||
}
|
}
|
||||||
|
@ -1330,7 +1306,7 @@ QssMessageBox::QssMessageBox( Icon icon, const QString &title, const QString &te
|
||||||
Qt::WindowFlags flags /*= Qt::Widget | Qt::FramelessWindowHint*/ )
|
Qt::WindowFlags flags /*= Qt::Widget | Qt::FramelessWindowHint*/ )
|
||||||
:QMessageBox(icon, title, text, buttons, 0, flags),m_parent(parent)
|
:QMessageBox(icon, title, text, buttons, 0, flags),m_parent(parent)
|
||||||
{
|
{
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
|
|
||||||
m_frame = new QFrame;
|
m_frame = new QFrame;
|
||||||
m_frame->setObjectName("messagebox");//css
|
m_frame->setObjectName("messagebox");//css
|
||||||
|
@ -1350,7 +1326,7 @@ QssMessageBox::QssMessageBox( Icon icon, const QString &title, const QString &te
|
||||||
m_titleBar->setIcon(style()->standardIcon((QStyle::StandardPixmap)(icon + 8)));
|
m_titleBar->setIcon(style()->standardIcon((QStyle::StandardPixmap)(icon + 8)));
|
||||||
|
|
||||||
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
||||||
vbox->setMargin(0);
|
// vbox->setMargin(0);
|
||||||
vbox->setSpacing(0);
|
vbox->setSpacing(0);
|
||||||
vbox->addWidget(m_titleBar);
|
vbox->addWidget(m_titleBar);
|
||||||
vbox->addWidget(this);
|
vbox->addWidget(this);
|
||||||
|
@ -1361,7 +1337,7 @@ QssMessageBox::QssMessageBox( Icon icon, const QString &title, const QString &te
|
||||||
QssMessageBox::QssMessageBox( QWidget *parent /*= 0*/ )
|
QssMessageBox::QssMessageBox( QWidget *parent /*= 0*/ )
|
||||||
:QMessageBox(parent),m_parent(parent)
|
:QMessageBox(parent),m_parent(parent)
|
||||||
{
|
{
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
|
|
||||||
m_frame = new QFrame;
|
m_frame = new QFrame;
|
||||||
m_frame->setObjectName("messagebox");//css
|
m_frame->setObjectName("messagebox");//css
|
||||||
|
@ -1374,7 +1350,7 @@ QssMessageBox::QssMessageBox( QWidget *parent /*= 0*/ )
|
||||||
m_titleBar->installEventFilter(this);
|
m_titleBar->installEventFilter(this);
|
||||||
|
|
||||||
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
||||||
vbox->setMargin(0);
|
// vbox->setMargin(0);
|
||||||
vbox->setSpacing(0);
|
vbox->setSpacing(0);
|
||||||
vbox->addWidget(m_titleBar);
|
vbox->addWidget(m_titleBar);
|
||||||
vbox->addWidget(this);
|
vbox->addWidget(this);
|
||||||
|
@ -1688,7 +1664,7 @@ QssDockWidget::QssDockWidget(QWidget *parent)
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
m_mousePressedInBorder(false)
|
m_mousePressedInBorder(false)
|
||||||
{
|
{
|
||||||
m_rcValid = QApplication::desktop()->availableGeometry();
|
m_rcValid = QGuiApplication::primaryScreen()->availableGeometry();
|
||||||
|
|
||||||
m_frame = new QFrame(parent);
|
m_frame = new QFrame(parent);
|
||||||
m_frame->setObjectName("dialog");//css
|
m_frame->setObjectName("dialog");//css
|
||||||
|
@ -1701,7 +1677,7 @@ QssDockWidget::QssDockWidget(QWidget *parent)
|
||||||
m_titleBar->installEventFilter(this);
|
m_titleBar->installEventFilter(this);
|
||||||
|
|
||||||
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
QVBoxLayout* vbox = new QVBoxLayout(m_frame);
|
||||||
vbox->setMargin(0);
|
// vbox->setMargin(0);
|
||||||
vbox->setSpacing(0);
|
vbox->setSpacing(0);
|
||||||
vbox->addWidget(m_titleBar);
|
vbox->addWidget(m_titleBar);
|
||||||
vbox->addWidget(this);
|
vbox->addWidget(this);
|
||||||
|
@ -1993,7 +1969,7 @@ QssMaskWidget::QssMaskWidget(QWidget *parent)
|
||||||
this->installEventFilter(this);
|
this->installEventFilter(this);
|
||||||
|
|
||||||
QPalette palette = this->palette();
|
QPalette palette = this->palette();
|
||||||
palette.setBrush(QPalette::Background, QColor(0,0,0));
|
palette.setBrush(QPalette::ColorRole::Dark, QColor(0,0,0));
|
||||||
this->setPalette(palette);
|
this->setPalette(palette);
|
||||||
this->setWindowOpacity(0.5);//设置窗口透明度
|
this->setWindowOpacity(0.5);//设置窗口透明度
|
||||||
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());//去掉标题栏
|
this->setWindowFlags(Qt::FramelessWindowHint | windowFlags());//去掉标题栏
|
||||||
|
@ -2073,19 +2049,3 @@ void QSSASyncProcess::Run(void *)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t CurrentDPI(QWidget* widget,int monitor)
|
|
||||||
{
|
|
||||||
float dpi = 1.0;
|
|
||||||
int screenNum = qApp->desktop()->screenNumber(widget);
|
|
||||||
qDebug()<<"current screen number is "<<screenNum;
|
|
||||||
auto screens = qApp->screens();
|
|
||||||
for(int i = 0;i < screens.size();i++){
|
|
||||||
if(screenNum >= 0){
|
|
||||||
QScreen* screen = qApp->screens().at(i);
|
|
||||||
dpi = screen->physicalDotsPerInch();
|
|
||||||
qDebug()<<screen->physicalDotsPerInch()<<screen->physicalDotsPerInchX()<<screen->physicalDotsPerInchY();
|
|
||||||
qDebug()<<screen->logicalDotsPerInch()<<screen->logicalDotsPerInchX()<<screen->logicalDotsPerInchY();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dpi;
|
|
||||||
}
|
|
||||||
|
|
9
Qss.h
9
Qss.h
|
@ -13,6 +13,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
#include <qnamespace.h>
|
||||||
|
|
||||||
#include "ui_qsstoast.h"
|
#include "ui_qsstoast.h"
|
||||||
#include "ui_process.h"
|
#include "ui_process.h"
|
||||||
|
@ -42,7 +43,6 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
// 获取当前dpi
|
// 获取当前dpi
|
||||||
uint16_t CurrentDPI(QWidget* widget,int monitor);
|
|
||||||
|
|
||||||
class QssTtitleBar : public QWidget
|
class QssTtitleBar : public QWidget
|
||||||
{
|
{
|
||||||
|
@ -113,7 +113,7 @@ class QssEventFilter
|
||||||
: public QAbstractNativeEventFilter
|
: public QAbstractNativeEventFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE
|
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -133,12 +133,12 @@ public:
|
||||||
typedef enum{
|
typedef enum{
|
||||||
EVENT_MOVE = 523,
|
EVENT_MOVE = 523,
|
||||||
} EVENT_CUSTOM;
|
} EVENT_CUSTOM;
|
||||||
QssMainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0,float scale = 1);
|
QssMainWindow(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Window,
|
||||||
|
float scale = 1);
|
||||||
virtual ~QssMainWindow();
|
virtual ~QssMainWindow();
|
||||||
void AdapteDpi();
|
void AdapteDpi();
|
||||||
QWidget *TitleBar();
|
QWidget *TitleBar();
|
||||||
void RangeObject();
|
void RangeObject();
|
||||||
void DetectDpiChange();
|
|
||||||
void ShowMask();
|
void ShowMask();
|
||||||
void HideMask();
|
void HideMask();
|
||||||
void show();
|
void show();
|
||||||
|
@ -429,6 +429,7 @@ public:
|
||||||
int Start(void*);
|
int Start(void*);
|
||||||
QThread &Thread();
|
QThread &Thread();
|
||||||
signals:
|
signals:
|
||||||
|
void Info(QString);
|
||||||
void DonePercent(int);
|
void DonePercent(int);
|
||||||
void Done();
|
void Done();
|
||||||
void StartRun(void *);
|
void StartRun(void *);
|
||||||
|
|
Loading…
Reference in New Issue