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. When is resizeEvent issued?
Forum Updated to NodeBB v4.3 + New Features

When is resizeEvent issued?

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 4 Posters 4.5k Views 1 Watching
  • 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.
  • O Offline
    O Offline
    ofmrew
    wrote on last edited by
    #1

    This is going back over thirty years, but I if I remember correctly before a window is opened a resize event is issued by the operating system (Window NT and OS2, not sure about Unix) I found it was not true for Qt . I want to update some transformation matrices when the window is resized including before when the window is displayed for the first time. I am using Qt6 and Qt Creator.

    JonBJ 1 Reply Last reply
    0
    • O ofmrew

      This is going back over thirty years, but I if I remember correctly before a window is opened a resize event is issued by the operating system (Window NT and OS2, not sure about Unix) I found it was not true for Qt . I want to update some transformation matrices when the window is resized including before when the window is displayed for the first time. I am using Qt6 and Qt Creator.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @ofmrew
      I don't know whether resizeEvent occurs before first show, but if not use showEvent as the event when a window is first shown and has a size.

      Axel SpoerlA 1 Reply Last reply
      0
      • Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by Axel Spoerl
        #3

        A resize event is posted whenever the size of a widget changes. Such changes can be programmatic, user interaction or propagated from your operating system. The latter ones vary depending on your OS type. It is not guaranteed that the construction of a widget triggers a resize event. In principle, a zero-to-X change would, a null-to-X change wouldn’t.
        Best way to find it out, is to install an eventFilter on your object, listen to the resize event and qDebug the result. Note that due to asynchronous event handling, especially on Linux platforms, the order of resize events can change and some can even be triggered twice. If you want your code to be platform independent, you have to check this for each platform and interpret accordingly. It is guaranteed that events cause the indicated change on a widget. A specific order, however, is not guaranteed. You have to keep that in mind :-)

        Software Engineer
        The Qt Company, Oslo

        1 Reply Last reply
        2
        • O Offline
          O Offline
          ofmrew
          wrote on last edited by
          #4

          Thanks for the quick answer. I resized the window with a qDebug in resizeEvent that did not show, then I realized that the window was promoted from QWidget to MyCanvas. Could QWidget not pass the the event to MyCanvas?

          Qt 6.2.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows"
          OS: Windows 11 Version 2009 [winnt version 10.0.22000]

          JonBJ Axel SpoerlA 2 Replies Last reply
          0
          • JonBJ JonB

            @ofmrew
            I don't know whether resizeEvent occurs before first show, but if not use showEvent as the event when a window is first shown and has a size.

            Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #5

            @JonB
            One of the OS dependent cases: when show() is called on the widget, resize comes in tow. Same when showing is OS or user triggered on Windows. Linux might cause a different order on user interactions.

            Software Engineer
            The Qt Company, Oslo

            1 Reply Last reply
            0
            • O ofmrew

              Thanks for the quick answer. I resized the window with a qDebug in resizeEvent that did not show, then I realized that the window was promoted from QWidget to MyCanvas. Could QWidget not pass the the event to MyCanvas?

              Qt 6.2.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows"
              OS: Windows 11 Version 2009 [winnt version 10.0.22000]

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @ofmrew
              If properly overridden (did you use override?) you should get resizeEvent in a class derived from QWidget.

              1 Reply Last reply
              1
              • O ofmrew

                Thanks for the quick answer. I resized the window with a qDebug in resizeEvent that did not show, then I realized that the window was promoted from QWidget to MyCanvas. Could QWidget not pass the the event to MyCanvas?

                Qt 6.2.2 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2019) on "windows"
                OS: Windows 11 Version 2009 [winnt version 10.0.22000]

                Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by Axel Spoerl
                #7

                @ofmrew
                I would propose listening to the QWidget.
                Is your event filter called at all? Do you install it from a class inheriting QObject and having the Q_Object macro at the right place?

                Software Engineer
                The Qt Company, Oslo

                O 1 Reply Last reply
                0
                • Axel SpoerlA Axel Spoerl

                  @ofmrew
                  I would propose listening to the QWidget.
                  Is your event filter called at all? Do you install it from a class inheriting QObject and having the Q_Object macro at the right place?

                  O Offline
                  O Offline
                  ofmrew
                  wrote on last edited by
                  #8

                  @Axel-Spoerl I just noted that the mainwindow resizes but not MyCanvas. I need to set it so that it also resizes when the mainwindow resizes. If that does not work then I will try the event filter. Thanks.

                  O 1 Reply Last reply
                  1
                  • O ofmrew

                    @Axel-Spoerl I just noted that the mainwindow resizes but not MyCanvas. I need to set it so that it also resizes when the mainwindow resizes. If that does not work then I will try the event filter. Thanks.

                    O Offline
                    O Offline
                    ofmrew
                    wrote on last edited by
                    #9

                    @ofmrew I use Qt Creator for all UI work. I added risizeEvent to MainWindow and I got the resizeEvent on initial opening. It looks as if MyCanvas never got notified. My next step is to put the canvas in a layout to cause a resize; however, in Designer that is easier said than done once the buttons and the promoted widget, canvas, have been added.

                    Axel SpoerlA 1 Reply Last reply
                    0
                    • O ofmrew

                      @ofmrew I use Qt Creator for all UI work. I added risizeEvent to MainWindow and I got the resizeEvent on initial opening. It looks as if MyCanvas never got notified. My next step is to put the canvas in a layout to cause a resize; however, in Designer that is easier said than done once the buttons and the promoted widget, canvas, have been added.

                      Axel SpoerlA Offline
                      Axel SpoerlA Offline
                      Axel Spoerl
                      Moderators
                      wrote on last edited by
                      #10

                      @ofmrew said in When is resizeEvent issued?:

                      @ofmrew It looks as if MyCanvas never got notified.

                      What exactly is MyCanvas? Your first mention of it is in your second post. Is it you own class inheriting from QWidget? As @JonB wrote, if it overrides correctly, it gets notified. Still there is nothing wrong about installing the event filter on the QWidget.

                      Software Engineer
                      The Qt Company, Oslo

                      O 1 Reply Last reply
                      0
                      • Axel SpoerlA Axel Spoerl

                        @ofmrew said in When is resizeEvent issued?:

                        @ofmrew It looks as if MyCanvas never got notified.

                        What exactly is MyCanvas? Your first mention of it is in your second post. Is it you own class inheriting from QWidget? As @JonB wrote, if it overrides correctly, it gets notified. Still there is nothing wrong about installing the event filter on the QWidget.

                        O Offline
                        O Offline
                        ofmrew
                        wrote on last edited by
                        #11

                        @Axel-Spoerl I want a white surface on which to draw, so I use Designer to place a Widget in the UI, then I promote that Widget to a new class MyCanvas, which does all the drawing. This allows me to use multiple Widgets, for different drawing purposes promoted to other classes. MyCanvas does inherit from QWidget.

                        I fixed the problem of MyCanvas resizing and I can say that MainWindow gets the resizeEvent before the MainWindow opens and all subsequent resizes. MyCanvas never gets a resizeEvent. I will install an event filter on QWidget. Since I have not done that before it I will need to do some research. I will let you know what I find.

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • O ofmrew

                          @Axel-Spoerl I want a white surface on which to draw, so I use Designer to place a Widget in the UI, then I promote that Widget to a new class MyCanvas, which does all the drawing. This allows me to use multiple Widgets, for different drawing purposes promoted to other classes. MyCanvas does inherit from QWidget.

                          I fixed the problem of MyCanvas resizing and I can say that MainWindow gets the resizeEvent before the MainWindow opens and all subsequent resizes. MyCanvas never gets a resizeEvent. I will install an event filter on QWidget. Since I have not done that before it I will need to do some research. I will let you know what I find.

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @ofmrew said in When is resizeEvent issued?:

                          to place a Widget in the UI

                          And hopefully add it to a layout or as central widget - otherwise there will be no automatic resizing and you will never get a resizeEvent() due to this.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          O 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @ofmrew said in When is resizeEvent issued?:

                            to place a Widget in the UI

                            And hopefully add it to a layout or as central widget - otherwise there will be no automatic resizing and you will never get a resizeEvent() due to this.

                            O Offline
                            O Offline
                            ofmrew
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher The steps are the following;
                            At bottom of MainWindow of Designer add button and spacers, select and add horizontal layout.
                            Above the button and on the MainWindow place a Widget, then right click on the MainWindow and add a vertical layout, which will be the layout for the central widget and the stop icon is removed from the central widget. What is shown in the Designer is not what you see when you execute the program. And it resizes when the MainWindow is resized, but never receives the resize message, only the MainWindow.

                            Recall that my objective is to calculate transformation matrices for each resize, including the first wheb the window is first opened. I could use signals and slots to signal MyCanvas each time the MainWindow is resized. Not as clean as getting a resize event.

                            Christian EhrlicherC 1 Reply Last reply
                            1
                            • O ofmrew

                              @Christian-Ehrlicher The steps are the following;
                              At bottom of MainWindow of Designer add button and spacers, select and add horizontal layout.
                              Above the button and on the MainWindow place a Widget, then right click on the MainWindow and add a vertical layout, which will be the layout for the central widget and the stop icon is removed from the central widget. What is shown in the Designer is not what you see when you execute the program. And it resizes when the MainWindow is resized, but never receives the resize message, only the MainWindow.

                              Recall that my objective is to calculate transformation matrices for each resize, including the first wheb the window is first opened. I could use signals and slots to signal MyCanvas each time the MainWindow is resized. Not as clean as getting a resize event.

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @ofmrew said in When is resizeEvent issued?:

                              MainWindow is resized, but never receives the resize message, only the MainWindow.

                              Then you're doing something wrong here.

                              Break it down to a simple QMainWindow without an ui-file, add your derived class as central widget and see if you get a resize event. Post the code here.

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              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