![]() If (event->oldState() = Qt::WindowNoState & QWindowStateChangeEvent* event = static_cast(evt) If (evt->type() = QEvent::WindowStateChange) However, for simple tasks like this, stick with frame-based animation. If you take a look here, you can see the quickest & dirtiest method to perform animation with Qt in action, and better ways to deal with animation. A for loop might do the trick, but if you need something fancy you'll end up using timers. To make it a bit more realistic, you should add some animation to resize the widget little by little. In other words, it's a transparent window which draws a rounded rectangle with a shadow and that's it. The idea behind the aero snap widget is very simple: a QWidget with transparent background and a custom painting procedure. To the right size of the screen it displays something that resembles an aero snap window (shown above). This demo creates a regular window for the user to interact with, and once it's maximized, it places itself to the left of the screen. It's not the most beautiful thing in the world, I know. The approach demonstrated in the source code below, creates and customizes a QWidget to make it behave and look like a aero snap window: The visual appearance can be replicated by drawing a transparent window with a shadow-ish border. The only other logical choice is to write a code that approximates this effect ourselves. To answer the second question, I don't think is possible to call the native Windows API and ask it politely to perform this effect on your window. This would be the time to create the aero snap widget and place it on the screen as a visual clue to the user. Once we identify a maximize request, we can figure out whether the application should be maximized (and anchored) to right, left or to the center of the screen. This event handler informs the new window/widget size that can be used for comparison with the desktop size, thus allowing us to know if the event was actually a maximize request. Of all these, the only one we care about is resizeEvent(). Void changeEvent(QEvent* evt) // and at last.Ī Qt application is first notified of a resizeEvent(), which is followed by a paintEvent() to draw the window (or widget), and only after everything has been displayed, changeEvent() is invoked to let you know the widget was maximized (maybe it's a little bit late to receive such notification, I don't know). Void paintEvent(QPaintEvent* event) // then second, In order to answer the first question, we must analyze which event handlers are triggered when the window is maximized: void resizeEvent(QResizeEvent* evt) // Invoked first, How to create an approximation of the aero snap effect? How to receive and handle a maximize event? In this answer I'll address what I believe are the 2 main challenges: I don't want to talk about every single detail involved in achieving this effect, not only there's a lot that goes on but you also mentioned you understand the logic to place the windows at their specific locations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |