Archived:Listening for screen orientation changes in Qt
This code snippet demonstrates how to listen for screen or layout orientation changes. When using Qt layout managers, they handle the layout changes and you generally do not need to worry about them.
On custom UI applications that do not use layout managers, you have to handle screen orientation and size changes by implementing a virtual QWidget::resizeEvent().
The event handler resizeEvent() of the base class QWidget is called whenever the user changes the screen mode. This event handler can be reimplemented in a subclass to receive widget resize events which are passed in the event parameter. QMainWindow is a subclass of QWidget and it contains resizeEvent() as well, so you can also get the resize event from QMainWindow if you implement it in your application.
This snippet can be self-signed.
- Install Qt SDK
Solution 1: Requesting the new size from QResizeEvent
Solution 2: Requesting the new size from QMainWindow's central widget
Layout orientation and size change are handled. You will get a notification when the user changes the screen mode.