Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. resizeEvent() only enabled with the window corner

resizeEvent() only enabled with the window corner

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fem_dev
    wrote on last edited by
    #1

    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

    SamurayHS 1 Reply Last reply
    0
    • F fem_dev

      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

      SamurayHS Offline
      SamurayHS Offline
      SamurayH
      wrote on last edited by SamurayH
      #2

      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.

      "قال رسول الله صلى الله عليه وسلم : " أحب الناس إلى الله أنفعهم للناس

      1 Reply Last reply
      2
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Three options.

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

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        F 1 Reply Last reply
        0
        • dheerendraD dheerendra

          Three options.

          1. Use windows flags Qt::FramelessWindowHint
          2. Use setFixedSize(...)
          3. Use event filters to filter the resize event.
          F Offline
          F Offline
          fem_dev
          wrote on last edited by
          #4

          @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?
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved