no message

qt6
zcy 2022-01-19 10:38:35 +08:00
parent 99ef959c68
commit 4490a55f31
2 changed files with 31 additions and 22 deletions

32
Qss.cpp
View File

@ -247,7 +247,6 @@ void QssMainWindow::OnMaxOrRestore(bool max)
setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_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));
QSize sizeHint = parentWidget()->sizeHint();
QDesktopWidget desktop; QDesktopWidget desktop;
QRect rc = desktop.availableGeometry(-1); QRect rc = desktop.availableGeometry(-1);
@ -259,12 +258,23 @@ void QssMainWindow::OnMaxOrRestore(bool max)
this->setFixedHeight(rc.height() - m_titleBar->height()); this->setFixedHeight(rc.height() - m_titleBar->height());
} }
} }
// 实际测试切换分辨率会触发这个slot
void QssMainWindow::DpiChange(qreal dpi) void QssMainWindow::PhisycalDpiChange(qreal dpi)
{ {
qDebug()<<"change dpi of QssMainWindow"<<dpi; qDebug()<<"dpi changed,reason: configuration "<<dpi;
} }
// 实际测试切换分辨率或者修改缩放比率都会触发这个slot
void QssMainWindow::LogicalDpiChange(qreal dpi)
{
qDebug()<<"dpi changed,reason: configuration "<<dpi;
m_dpi_ratio = 96/dpi;
qDebug()<<"factor is "<<m_dpi_ratio;
auto parent = this->parentWidget();
parent->setGeometry(parent->geometry().x(),parent->geometry().y(),
parent->geometry().width()*m_dpi_ratio,
parent->geometry().height()*m_dpi_ratio);
}
QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* = 0*/,float scale) QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* = 0*/,float scale)
@ -317,7 +327,11 @@ QssMainWindow::QssMainWindow(QWidget *parent/* = 0*/, Qt::WindowFlags flags/* =
if(nullptr != mCurrentScreen){ if(nullptr != mCurrentScreen){
connect(mCurrentScreen, connect(mCurrentScreen,
SIGNAL(physicalDotsPerInchChanged(qreal)), SIGNAL(physicalDotsPerInchChanged(qreal)),
this,SLOT(DpiChange(qreal))); this,SLOT(PhisycalDpiChange(qreal)));
connect(mCurrentScreen,
SIGNAL(logicalDotsPerInchChanged(qreal)),
this,SLOT(LogicalDpiChange(qreal)));
} }
rangeObjectList(m_frame,0); rangeObjectList(m_frame,0);
return; return;
@ -333,6 +347,11 @@ QWidget *QssMainWindow::TitleBar()
return m_titleBar; return m_titleBar;
} }
void QssMainWindow::RangeObject()
{
rangeObjectList(m_frame,0);
}
void QssMainWindow::DetectDpiChange() void QssMainWindow::DetectDpiChange()
{ {
int screenNum = qApp->desktop()->screenNumber(this); int screenNum = qApp->desktop()->screenNumber(this);
@ -428,7 +447,6 @@ void QssMainWindow::showNormal()
void QssMainWindow::setWindowTitle( QString title ) void QssMainWindow::setWindowTitle( QString title )
{ {
//m_frame->setWindowTitle(title);
m_titleBar->setTitle(title); m_titleBar->setTitle(title);
} }
@ -467,8 +485,6 @@ void QssMainWindow::onMouseMoveEvent(QMouseEvent * ev)
setCursorShape(CalCursorPos(ev->pos(),CalCursorCol(ev->pos()))); setCursorShape(CalCursorPos(ev->pos(),CalCursorCol(ev->pos())));
} }
QPoint ptCurrentPos = QCursor::pos(); QPoint ptCurrentPos = QCursor::pos();
QPoint ptMoveSize = ptCurrentPos - m_ptViewMousePos;
QRect rtTempGeometry = this->geometry();
QRect rtCentralGeo = this->centralWidget()->geometry(); QRect rtCentralGeo = this->centralWidget()->geometry();
QRect rtMainWindow = this->geometry(); QRect rtMainWindow = this->geometry();
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);

19
Qss.h
View File

@ -26,7 +26,9 @@
class QPushButton; class QPushButton;
class QLabel; class QLabel;
class QMouseEvent; class QMouseEvent;
#define STANDARD_DPI 96.0 #define STANDARD_DPI 96.0
#ifndef WM_DPICHANGED #ifndef WM_DPICHANGED
#define WM_DPICHANGED 0x02e0 #define WM_DPICHANGED 0x02e0
#endif #endif
@ -108,19 +110,7 @@ class QssEventFilter
{ {
public: public:
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *) Q_DECL_OVERRIDE
{/*
MSG* pMsg = reinterpret_cast<MSG*>(message);
if(nullptr != pMsg){
switch (pMsg->message)
{ {
case WM_DPICHANGED:
{
qDebug()<<"DPI CHANGED";
}
}
}*/
// TODO: filter out or modify msg struct here
return false; return false;
} }
}; };
@ -131,7 +121,9 @@ class QssMainWindow : public QMainWindow
public slots: public slots:
void OnMaxOrRestore(bool max); void OnMaxOrRestore(bool max);
void DpiChange(qreal); void PhisycalDpiChange(qreal);
void LogicalDpiChange(qreal);
public: public:
typedef enum{ typedef enum{
EVENT_MOVE = 523, EVENT_MOVE = 523,
@ -140,6 +132,7 @@ public:
virtual ~QssMainWindow(); virtual ~QssMainWindow();
QWidget *TitleBar(); QWidget *TitleBar();
void RangeObject();
void DetectDpiChange(); void DetectDpiChange();
void ShowMask(); void ShowMask();
void HideMask(); void HideMask();