Qt::FramelessWindowHint make QT_DEVICE_PIXEL_RATIO error
-
Hi and welcome to devnet,
What OS/Qt version are you using ?
What isn't clickable ?
-
Can you be more precise ?
-
@SGaist Sorry,It's my error,I overwrite QMainWindow's nativeEvent function,but I don't know
int xPos = GET_X_LPARAM(message->lParam) - this->frameGeometry().x();
the xPos is depend on QT_DEVICE_PIXEL_RATIO。
e.g
QT_DEVICE_PIXEL_RATIO=1,xPos = 100.
QT_DEVICE_PIXEL_RATIO=2,xPos = 200.but this->width() don't depends on QT_DEVICE_PIXEL_RATIO。so my code make a error.
bool RCMainWindow::winEvent(MSG *message, long *result) { switch (message->message) { case WM_NCHITTEST: int xPos = GET_X_LPARAM(message->lParam) - this->frameGeometry().x(); int yPos = GET_Y_LPARAM(message->lParam) - this->frameGeometry().y(); if (this->childAt(xPos, yPos) == 0) { *result = HTCAPTION; } else { return false; } if (xPos >=0 && xPos < 5) *result = HTLEFT; if (xPos >(this->width() - 5) && xPos < this->width() + 5) *result = HTRIGHT; if (yPos >= 0 && yPos < 5) *result = HTTOP; if (yPos >(this->height() - 5) && yPos < (this->height() + 5)) *result = HTBOTTOM; if (xPos >= 0 && xPos < 5 && yPos >= 0 && yPos < 5) *result = HTTOPLEFT; if (xPos >(this->width() - 5) && xPos < (this->width() + 5) && yPos >= 0 && yPos < 5) *result = HTTOPRIGHT; if (xPos >= 0 && xPos < 5 && yPos >(this->height() - 5) && yPos < (this->height() + 5)) *result = HTBOTTOMLEFT; if (xPos >(this->width() - 5) && xPos < (this->width() + 5) && yPos >(this->height() - 5) && yPos < (this->height() + 5)) *result = HTBOTTOMRIGHT; return true; } return false; }
I need to fix it 。
bool RCMainWindow::winEvent(MSG *message, long *result) { switch (message->message) { case WM_NCHITTEST: int xPos = GET_X_LPARAM(message->lParam) - this->frameGeometry().x(); int yPos = GET_Y_LPARAM(message->lParam) - this->frameGeometry().y(); int ratio = g_pApp->devicePixelRatio(); if(ratio > 1) { xPos = xPos / ratio; yPos = yPos / ratio; } if (this->childAt(xPos, yPos) == 0) { *result = HTCAPTION; } else { return false; } if (xPos >=0 && xPos < 5) *result = HTLEFT; if (xPos >(this->width() - 5) && xPos < this->width() + 5) *result = HTRIGHT; if (yPos >= 0 && yPos < 5) *result = HTTOP; if (yPos >(this->height() - 5) && yPos < (this->height() + 5)) *result = HTBOTTOM; if (xPos >= 0 && xPos < 5 && yPos >= 0 && yPos < 5) *result = HTTOPLEFT; if (xPos >(this->width() - 5) && xPos < (this->width() + 5) && yPos >= 0 && yPos < 5) *result = HTTOPRIGHT; if (xPos >= 0 && xPos < 5 && yPos >(this->height() - 5) && yPos < (this->height() + 5)) *result = HTBOTTOMLEFT; if (xPos >(this->width() - 5) && xPos < (this->width() + 5) && yPos >(this->height() - 5) && yPos < (this->height() + 5)) *result = HTBOTTOMRIGHT; return true; } return false; }