|  | Home · Overviews · Examples

# SIP Dialog Example

The SIP Dialog example shows how to create a dialog that is aware of the Windows Mobile SIP (Software Input Panel) and reacts to it.

Sometimes it is necessary for a dialog to take the SIP into account, as the SIP may hide important input widgets. The SIP Dialog Example shows how a `Dialog` object, `dialog`, can be resized accordingly if the SIP is opened, by embedding the contents of `dialog` in a QScrollArea.

## Dialog Class Definition

The `Dialog` class is a subclass of QDialog that implements a public slot, `desktopResized()`, and a public function, `reactToSIP()`. Also, it holds a private instance of QRect, `desktopGeometry`. Missing snippet: dialogs/sipdialog/dialog.h.

## Dialog Class Implementation

In the constructor of `Dialog`, we start by obtaining the available geometry of the screen with availableGeometry(). The parameter used is `0` to indicate that we require the primary screen. Missing snippet: dialogs/sipdialog/dialog.cpp. We set the window's title to "SIP Dialog Example" and declare a QScrollArea object, `scrollArea`. Next we instantiate a QGroupBox, `groupBox`, with `scrollArea` as its parent. The title of `groupBox` is also set to "SIP Dialog Example". A QGridLayout object, `gridLayout`, is then used as `groupBox`'s layout.

We create a QLineEdit, a QLabel and a QPushButton and we set the minimumWidth property to 220 pixels, respectively. Missing snippet: dialogs/sipdialog/dialog.cpp. Also, all three widgets' text are set accordingly. The verticalSpacing property of `gridLayout` is set based on the height of `desktopGeometry`. This is to adapt to the different form factors of Windows Mobile. Then, we add our widgets to the layout. Missing snippet: dialogs/sipdialog/dialog.cpp. The `scrollArea`'s widget is set to `groupBox`. We use a QHBoxLayout object, `layout`, to contain `scrollArea`. The `Dialog`'s layout is set to `layout` and the scroll area's horizontal scroll bar is turned off. Missing snippet: dialogs/sipdialog/dialog.cpp. The following signals are connected to their respective slots:

- `button`'s pressed() signal to QApplication's closeAllWindows() slot,
- QDesktopWidget's workAreaResized() signal to `dialog`'s `desktopResized()` slot.

Missing snippet: dialogs/sipdialog/dialog.cpp. The `desktopResized()` function accepts an integer, `screen`, corresponding to the screen's index. We only invoke `reactToSIP()` if `screen` is the primary screen (e.g. index = 0). Missing snippet: dialogs/sipdialog/dialog.cpp. The `reactToSIP()` function resizes `dialog` accordingly if the desktop's available geometry changed vertically, as this change signifies that the SIP may have been opened or closed. Missing snippet: dialogs/sipdialog/dialog.cpp. If the height has decreased, we unset the maximized window state. Otherwise, we set the maximized window state. Lastly, we update `desktopGeometry` to the desktop's available geometry.

## The main() function

`main()` The `main()` function for the SIP Dialog example instantiates `Dialog` and invokes its exec() function. Missing snippet: dialogs/sipdialog/main.cpp. Note: Although this example uses a dialog, the techniques used here apply to all top-level widgets respectively.