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

resizeEvent() only enabled with the window corner



  • I would like to know how to block/filter the vertical and horizontal resize events and call the resizeEvent() when the user try to resize the QMainWindow using the window corner (Image below).

    I tried to use the setFixedSize(), but this method blocks ALL resizes events.

    void MainWindow::resizeEvent(QResizeEvent *event)
    {
        qDebug() << "SIZE = " << event->size();
    }
    

    How can I do that?

    4c9dd9f7-7f47-4ab2-8961-4c239c00580a-image.png



  • Hi,
    I'm not sure you can achieve that with resizeEvent. But I'm certain that it's possible throw the nativeEvent handler..., at least for Windows:

    add this:

    #include <Windows.h>
    

    and this:

    private:
        RECT* m_winRect;
    

    add this, in the constructor:

    m_winRect = new RECT;
    GetWindowRect((HWND)winId(), m_winRect);
    

    and finally, handle the native resizing event...

    bool MyWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
    {
        // for a message coming from Windows
        if(eventType == "windows_generic_MSG"){
            MSG* msg = static_cast<MSG*>(message);
            // the native resizing event
            if(msg->message == WM_SIZING){
                RECT* rect = (RECT*)msg->lParam;
                if(msg->wParam == WMSZ_BOTTOMRIGHT) //bottom right corner resizing...
                    *m_winRect = *rect; //allow resize
                else
                    *rect = *m_winRect; //block resize    
    
               *result = true;
                return true;
            }
        }  
    
        return false;
    }
    

    And now the user can resize the window using the bottom right corner only.

    You can read more about the Qt native event here, and about WM_SIZING here.


  • Qt Champions 2017

    Three options.

    1. Use windows flags Qt::FramelessWindowHint
    2. Use setFixedSize(...)
    3. Use event filters to filter the resize event.


  • @dheerendra thank you for your quick answer.

    But I want to block ONLY the vertical and horizontal resize, but I want TO ENABLE just the window corner resize, like a proportional image resize keeping the window aspect ratio.

    • option 1: blocks all
    • option 2: blocks all
    • option 3: I have the MainWindow::resizeEvent(QResizeEvent *event) method, but I don't know how to filter this specific window corner resize event. Could you help me?

Log in to reply