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?
-
Hi,
I'm not sure you can achieve that withresizeEvent
. But I'm certain that it's possible throw thenativeEvent
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.
-
Three options.
- Use windows flags Qt::FramelessWindowHint
- Use setFixedSize(...)
- 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?