Results 1 to 10 of 10

Thread: Resizing a maximized, custom-frame window

  1. #1
    Join Date
    Oct 2006
    Location
    Austin, Texas, USA
    Posts
    18
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Resizing a maximized, custom-frame window

    I have an application that uses a custom window frame that is implemented by hiding the main application frame (via Qt::FramelessWindowHint) and giving it an appropriate mask.

    Everything is working properly, except when I try to maximize the application. When maximized, the top border of the custom window is offset by the height of the masked Windows frame titlebar. I've tried using the setGeometry() command on the main window to offset the custom window frame slightly when maximized, but for some reason it doesn't want to set the new geometry if an x-coordinate of less than 5 is given (I'd like to keep the x coordinate at 0 and have the y coordinate be the negative of whatever the masked Windows frame titlebar is).

    Any help on this is greatly appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a maximized, custom-frame window

    AFAIK you can't move a window outside the screen in Windows, so if the frame still is there, you won't be able to move it. You may set your widget to full screen mode, maybe that helps (there will be no border at all then). But why do you need the mask? Doesn't the frameless window hint disable the decoration?

  3. #3
    Join Date
    Oct 2006
    Location
    Austin, Texas, USA
    Posts
    18
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Resizing a maximized, custom-frame window

    You are correct, the frameless window removes the window decoration, but I have a custom window decoration that is setup in a 3x3 grid in the main window. The mask is then applied to give the window a curved look on the edges instead of it being a big rectangle.

    I've tried using the full-screen method, but doing this causes the context menu on the Windows taskbar to disable the "Restore" option that restores the application back to its original size.

    Also, I noticed that if I make the following call:
    Qt Code:
    1. setGeometry(rect());
    2. updateGeometry();
    To copy to clipboard, switch view to plain text mode 

    It will correctly shift the application window up to the top of the screen, but it will leave a space below the application. Attempting to manually set the height to a different value will cause the window to shift back down again. This call is in the resizeEvent() method of my main window, and I have a boolean variable that gets set to avoid an infinite loop in resizing the window.

    One thing I'm noticing is that something else is receiving the maximized signal before my QMainWindow. Does Windows handle this event and attempt a resize before it notifies the application? If I can intercept this call, then maybe I can redefine how the application can handle it before any resize is attempted. By the time resizeEvent() is called in my code, the application already thinks it's maximized.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a maximized, custom-frame window

    Maybe you could just
    Qt Code:
    1. setGeometry(QDesktopWidget().availableGeometry());
    To copy to clipboard, switch view to plain text mode 
    ?

  5. #5
    Join Date
    Oct 2006
    Location
    Austin, Texas, USA
    Posts
    18
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Resizing a maximized, custom-frame window

    Ok, this worked:

    Qt Code:
    1. showFullScreen();
    2. setGeometry(qApp->desktop()->availableGeometry());
    3. updateGeometry();
    To copy to clipboard, switch view to plain text mode 

    However, when you right-click on the application button in the Windows taskbar it doesn't have the "Restore" option highlighted... Is there any way to manually enable those options?

    Also, it would be a lot easier if I blocked the call for maximizing the application right when the application receives it and before any resize takes place; but for some reason I can't ignore the event. Here's the code I have in place that catches the maximize attempt:

    Qt Code:
    1. bool MyMainWindow::event(QEvent* e)
    2. {
    3. if(e->type() == QEvent::WindowStateChange && windowState() == Qt::WindowMaximized)
    4. {
    5. // Manually resize the GUI using the above method.
    6. e->ignore();
    7. return false;
    8. }
    9. else
    10. return QWidget::event(e);
    11. }
    To copy to clipboard, switch view to plain text mode 
    Even though I specify that the event should be ignored, the window still tries to maximize which causes a brief moment of window resizing up, then down, then back up to full-screen. Is there something else I need to do to ignore the event?

    Thanks!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a maximized, custom-frame window

    Quote Originally Posted by Claymore View Post
    However, when you right-click on the application button in the Windows taskbar it doesn't have the "Restore" option highlighted...
    Because it's not maximized. "Maximized" doesn't mean every situation when a widget fills the whole available space. Maximizing is done by the window manager and any change to the geometry causes the window to leave the maximized state.

    Is there any way to manually enable those options?
    I don't think so.

    Also, it would be a lot easier if I blocked the call for maximizing the application right when the application receives it and before any resize takes place; but for some reason I can't ignore the event.
    State change events are just a notification, they are spontaneous events.

    Even though I specify that the event should be ignored, the window still tries to maximize which causes a brief moment of window resizing up, then down, then back up to full-screen. Is there something else I need to do to ignore the event?
    I don't think you can ignore the event.

    Do you really need that "restore" option enabled? Can't you just have a button or something?

  7. #7
    Join Date
    Oct 2006
    Location
    Austin, Texas, USA
    Posts
    18
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Resizing a maximized, custom-frame window

    Do you really need that "restore" option enabled? Can't you just have a button or something?
    It's not so much my preference but more the preference of the customers involved, in this case a marketing department . I'll keep chugging away at this and see if I can't find some sort of solution. The reason why I think this should be possible (or at least I hope it is ) is that other applications such as Windows Media Player seem to use this similar method of hiding the window frame and masking off specific areas of the window, but somehow they can handle going to fullscreen just fine.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Resizing a maximized, custom-frame window

    Fullscreen or maximize? These two differ you know...

    And I think you don't have any problem maximizing the window and having "restore" enabled, the problem is you want to move the window then. Maybe try focusing on how to obtain the effect you need (whatever it is) without manipulating the geometry of the window once it is maximized?

  9. #9
    Join Date
    Oct 2006
    Location
    Austin, Texas, USA
    Posts
    18
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Resizing a maximized, custom-frame window

    You are correct - I meant maximized, not full screen (head's becoming frazzled from trying to get this working properly ).

  10. #10

    Default Re: Resizing a maximized, custom-frame window

    You could intercept win messages, overrride winEvent() in your window. This will let you set the width/height for system "maximize" function, so you could make it fullscreen.

    In the comments are provided links to msdn where you can read more about the MINMAXINFO structure and its variables.

    Qt Code:
    1. #include <windows.h>
    2.  
    3. bool MainWindow::winEvent ( MSG * message, long * result )
    4. {
    5. switch (message->message)
    6. {
    7. case WM_GETMINMAXINFO: {
    8.  
    9. // GetSysemMetrics(): http://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx
    10. // ptMinTrackSize - The minimum tracking width/height of a window, in pixels.
    11. // The user cannot drag the window frame to a size smaller than these dimensions.
    12. // ptMaxTrackSize - The default maximum width/height of a window that has a caption
    13. // and sizing borders, in pixels. This metric refers to the entire desktop. The user cannot
    14. // drag the window frame to a size larger than these dimensions.
    15.  
    16. // WM_GETMINMAXINFO: http://msdn.microsoft.com/en-us/library/ms632626(VS.85).aspx
    17. // MINMAXINFO structure: http://msdn.microsoft.com/en-us/library/ms632605(VS.85).aspx
    18.  
    19. MINMAXINFO *mmi = (MINMAXINFO*) (message->lParam);
    20.  
    21. QDesktopWidget desktopWidget;
    22. QRect desktop = desktopWidget.availableGeometry();
    23.  
    24. mmi->ptMaxSize.x = desktop.width();
    25. mmi->ptMaxSize.y = desktop.height();
    26.  
    27. mmi->ptMaxPosition.x = desktop.x();
    28. mmi->ptMaxPosition.y = desktop.y();
    29.  
    30. mmi->ptMinTrackSize.x = this->minWidth; // minimum width for your window
    31. mmi->ptMinTrackSize.y = this->minHeight; // minimum height for your window
    32.  
    33. mmi->ptMaxTrackSize.x = desktop.width();
    34. mmi->ptMaxTrackSize.y = desktop.height();
    35.  
    36. result = 0;
    37.  
    38. return true;
    39. break;
    40. }
    41. return false;
    42. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Main window with custom buttons ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2006, 06:32
  2. [QT4] Any way to disable window resizing ?
    By Amalsek in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2006, 11:36
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.