![]() |
Home · Examples |
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.
![]() | ![]() |
class Dialog : public QDialog { Q_OBJECT public: Dialog(); void reactToSIP(); private: QRect desktopGeometry; public slots: void desktopResized(int screen); };
Dialog::Dialog() { desktopGeometry = QApplication::desktop()->availableGeometry(0); setWindowTitle(tr("SIP Dialog Example")); QScrollArea *scrollArea = new QScrollArea(this); QGroupBox *groupBox = new QGroupBox(scrollArea); groupBox->setTitle(tr("SIP Dialog Example")); QGridLayout *gridLayout = new QGridLayout(groupBox); groupBox->setLayout(gridLayout);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.
The following code example is written in c++.
QLineEdit* lineEdit = new QLineEdit(groupBox); lineEdit->setText(tr("Open and close the SIP")); lineEdit->setMinimumWidth(220); QLabel* label = new QLabel(groupBox); label->setText(tr("This dialog resizes if the SIP is opened")); label->setMinimumWidth(220); QPushButton* button = new QPushButton(groupBox); button->setText(tr("Close Dialog")); button->setMinimumWidth(220);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.
if (desktopGeometry.height() < 400) gridLayout->setVerticalSpacing(80); else gridLayout->setVerticalSpacing(150); gridLayout->addWidget(label); gridLayout->addWidget(lineEdit); gridLayout->addWidget(button);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.
scrollArea->setWidget(groupBox); QHBoxLayout* layout = new QHBoxLayout(); layout->addWidget(scrollArea); setLayout(layout); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);The following signals are connected to their respective slots:
connect(button, SIGNAL(pressed()), qApp, SLOT(closeAllWindows())); connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), this, SLOT(desktopResized(int))); }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).Error parsing snippet. 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.Error parsing snippet. 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.
Copyright © 2008 Nokia | Trademarks | Qt Jambi 4.4.3_01 |