Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt::FramelessWindowHint make QT_DEVICE_PIXEL_RATIO error



  • When I set window flags is Qt::FramelessWindowHint and set QT_DEVICE_PIXEL_RATIO=2, my application really scaled bigger,but have some area don't click.
    If I remove window flags, It's become normal.

    Can I fix it?
    How fix it?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What OS/Qt version are you using ?

    What isn't clickable ?



  • @SGaist I am using win10 and Qt5.6.0.
    Isn't clickable is part of application's window don't get focus when mouse move to there.


  • Lifetime Qt Champion

    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;
    }
    


  • @SGaist Thank you! I solved my problem.
    How change this topic's status ?



  • @SGaist Now I had other problem.
    When I set QT_DEVICE_PIXEL_RATIO = 2 and windowflag = Qt::FramelessWindowHint.
    then QMainWindow's show max error that don't full all screen.

    normal.jpg
    max.jpg
    code


Log in to reply