diff --git a/Qss.cpp b/Qss.cpp index f143170..c8dcf54 100644 --- a/Qss.cpp +++ b/Qss.cpp @@ -161,6 +161,10 @@ void QssTtitleBar::mouseMoveEvent( QMouseEvent * ev ) QPoint globalPt = ev->globalPos(); QPoint movePt = globalPt - m_pressedPos;//FrameglobalPos parentWidget()->move(movePt);//globalPos + QssMainWindow *parent = static_cast(parentWidget()); + if(nullptr != parent){ + parent->DetectDpiChange(); + } return ; } @@ -242,10 +246,15 @@ void QssMainWindow::OnMaxOrRestore(bool max) } } +void QssMainWindow::DpiChange(qreal dpi) +{ + qDebug()<<"change dpi of QssMainWindow"<setStyleSheet("QWidget{background-color:rgba(1,1,1,0.3);}"); mShadowMask->hide(); + int screenNum = qApp->desktop()->screenNumber(this); + qDebug()<<"current screen number is "<screens().at(screenNum); + if(nullptr != mCurrentScreen){ + connect(mCurrentScreen, + SIGNAL(physicalDotsPerInchChanged(qreal)), + this,SLOT(DpiChange(qreal))); + } return; } @@ -301,6 +318,17 @@ QWidget *QssMainWindow::TitleBar() return m_titleBar; } +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() { mShadowMask->setGeometry(0, 0, this->width(),this->height()); //遮罩窗口位置 @@ -586,7 +614,6 @@ bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){ } else if (obj == m_titleBar) { -// QCoreApplication::sendEvent(this,new QEvent(QEvent::Type::Resize)); if (ev->type() == QEvent::Enter) { m_left = false; @@ -632,26 +659,6 @@ bool QssMainWindow::eventFilter(QObject * obj, QEvent * ev){ } -bool QssMainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) -{ - - MSG* pMsg = reinterpret_cast(message); - switch (pMsg->message) - { - case WM_DPICHANGED: - { - qDebug()<<"DPI CHANGED"; - /*DWORD dpi = LOWORD(pMsg->wParam); - //WId id = WINDOW_WINID; - //if (DPIHelper()->DPIChanged(dpi, id)) - { - ScaleChanged(DPIHelper()->GetDPIScale(id)); - RefrushSheet(this, id); - }*/ - } - } - return false; -} void QssMainWindow::ScaleChanged(float scale) { @@ -1801,25 +1808,16 @@ void QSSASyncProcess::Run(void *) uint16_t CurrentDPI(QWidget* widget,int monitor) { float dpi = 1.0; - int screenNum = qApp->desktop()->screenNumber(widget); //this 表示当前的窗口 QWidget类型 + int screenNum = qApp->desktop()->screenNumber(widget); + qDebug()<<"current screen number is "<screens(); - qDebug()<<"screenNum"<= 0){ - QScreen* screen = qApp->screens().at(monitor); - dpi = screen->physicalDotsPerInch(); - qDebug()<physicalDotsPerInch()<physicalDotsPerInchX()<physicalDotsPerInchY(); - qDebug()<logicalDotsPerInch()<logicalDotsPerInchX()<logicalDotsPerInchY(); + for(int i = 0;i < screens.size();i++){ + if(screenNum >= 0){ + QScreen* screen = qApp->screens().at(i); + dpi = screen->physicalDotsPerInch(); + qDebug()<physicalDotsPerInch()<physicalDotsPerInchX()<physicalDotsPerInchY(); + qDebug()<logicalDotsPerInch()<logicalDotsPerInchX()<logicalDotsPerInchY(); + } } - - int currentScreenWidth = QApplication::desktop()->width(); - int currentScreenHeight = QApplication::desktop()->height(); -//或者 - QDesktopWidget* desktopWidget = QApplication::desktop(); - //获取可用桌面大小 - QRect deskRect = desktopWidget->availableGeometry(); - //获取设备屏幕大小 - QRect screenRect = desktopWidget->screenGeometry(); - auto screenX = screenRect.width(); - auto screenY = screenRect.height(); return dpi; }