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. Is it possible to intercept maximizing the main window?
QtWS25 Last Chance

Is it possible to intercept maximizing the main window?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 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.
  • JonBJ Online
    JonBJ Online
    JonB
    wrote on last edited by JonB
    #1

    Is there a way to intercept a QMainWindow being maximized, and change behaviour?

    I want main window to still have the usual native window "maximize" button for user to click, but I want it to set size to a particular value rather than actually maximizing it. Linux & Windows.

    (Why? Well, before you challenge me: during development I allow specification of a desktop size which relates to some other (smaller) screen device I wish to support, so that I can emulate it and see what things look like. I'd like this convenient way to be able to set it to the maximum size specified for that desktop. Note that just setting a fixed size is not acceptable: I must still be able to resize, at least to make it smaller then the emulated desktop.)

    I don't know whether one can do this --- intercept native maximumization button, and then change the event such that it does not really maximize but instead resizes to a certain size?

    Or, it occurs to me, maybe I have seen in other native apps that they are able to "limit" the main window's maximum size to something less than the desktop (how?) and then I wouldn't have to intercept any event?

    EDIT: I can see that QMainWindow::setMaximumSize() works for drag-resizing, that might be usable but I'd still like to be able to limit when the user clicks the maximize button, which ignores that setting and fills the whole real desktop.

    EDIT2: I have tried (under Linux, no access to Windows) both changeEvent() & eventFilter(). I receive the WindowStateChange maximize events but no amount of accepting/ignoring/returning true actually "cancels" the maximization/minimization. See e.g. https://www.qtcentre.org/threads/12300-Unable-to-handle-WindowStateChange-events. In fact I seem to receive both of these after I see the window get maximized, is the maximize-from-window-button something which gets pre-handled by the native windowing system before it gets passed to Qt?

    Pl45m4P 1 Reply Last reply
    0
    • JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #4

      So the conclusion is: no, from Qt (as opposed to some native code) you cannot "intercept" window maximization in the way I mean, i.e. before the windowing system does the actual maximization: Qt only sends you the signal after that, to react on.

      1 Reply Last reply
      0
      • JonBJ JonB

        Is there a way to intercept a QMainWindow being maximized, and change behaviour?

        I want main window to still have the usual native window "maximize" button for user to click, but I want it to set size to a particular value rather than actually maximizing it. Linux & Windows.

        (Why? Well, before you challenge me: during development I allow specification of a desktop size which relates to some other (smaller) screen device I wish to support, so that I can emulate it and see what things look like. I'd like this convenient way to be able to set it to the maximum size specified for that desktop. Note that just setting a fixed size is not acceptable: I must still be able to resize, at least to make it smaller then the emulated desktop.)

        I don't know whether one can do this --- intercept native maximumization button, and then change the event such that it does not really maximize but instead resizes to a certain size?

        Or, it occurs to me, maybe I have seen in other native apps that they are able to "limit" the main window's maximum size to something less than the desktop (how?) and then I wouldn't have to intercept any event?

        EDIT: I can see that QMainWindow::setMaximumSize() works for drag-resizing, that might be usable but I'd still like to be able to limit when the user clicks the maximize button, which ignores that setting and fills the whole real desktop.

        EDIT2: I have tried (under Linux, no access to Windows) both changeEvent() & eventFilter(). I receive the WindowStateChange maximize events but no amount of accepting/ignoring/returning true actually "cancels" the maximization/minimization. See e.g. https://www.qtcentre.org/threads/12300-Unable-to-handle-WindowStateChange-events. In fact I seem to receive both of these after I see the window get maximized, is the maximize-from-window-button something which gets pre-handled by the native windowing system before it gets passed to Qt?

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by Pl45m4
        #2

        @JonB said in Is it possible to intercept maximizing the main window?:

        I have seen in other native apps that they are able to "limit" the main window's maximum size to something less than the desktop (how?)

        You are talking about this?! Software DesktopCoral.

        If ignoring the event doesnt work, I dont know how they have done it and if it is even possible in Qt. I fear, the Window Manager will kick in every time and set the window size maximized to desktop.

        @JonB said in Is it possible to intercept maximizing the main window?:

        In fact I seem to receive both of these after I see the window get maximized

        This might be a little dirty, but when the eventHandler intercepts AFTER the window is maximized by OS, why not try to set your size immediately after that? Like this


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        JonBJ 1 Reply Last reply
        0
        • Pl45m4P Pl45m4

          @JonB said in Is it possible to intercept maximizing the main window?:

          I have seen in other native apps that they are able to "limit" the main window's maximum size to something less than the desktop (how?)

          You are talking about this?! Software DesktopCoral.

          If ignoring the event doesnt work, I dont know how they have done it and if it is even possible in Qt. I fear, the Window Manager will kick in every time and set the window size maximized to desktop.

          @JonB said in Is it possible to intercept maximizing the main window?:

          In fact I seem to receive both of these after I see the window get maximized

          This might be a little dirty, but when the eventHandler intercepts AFTER the window is maximized by OS, why not try to set your size immediately after that? Like this

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #3

          @Pl45m4

          AFTER the window is maximized by OS, why not try to set your size immediately after that

          Because I first see the window redrawn to fill my real desktop, and then I make it normal again and it gets redrawn at the emulated size. Which would not look good if I needed this in production :)

          ATM that is what I am doing because I can't find (and I've done a lot of Googling) any way to stop the windowing system from maximizing before it gets to Qt. I want to leave this issue open for a bit in case someone else knows better....

          1 Reply Last reply
          1
          • JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #4

            So the conclusion is: no, from Qt (as opposed to some native code) you cannot "intercept" window maximization in the way I mean, i.e. before the windowing system does the actual maximization: Qt only sends you the signal after that, to react on.

            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