English Български

How to make a Modal Dialog with Qt Components on MeeGo

There is a QML Dialog element [harmattan-dev.nokia.com] in Qt Quick Components in MeeGo 1.2 Harmattan API. But this dialog is not modal – i.e. it can be closed by pressing on any part of the dialog’s window, not only on the buttons. Such behavior is not good in some cases – any accidental touch can close the dialog’s window. There is no way through the API to make this dialog not respond on background clicks.

Surely we can make such a window ourselves without using Dialog element, but it is not a quick or proper way.

From the Dialog’s source it can be discovered that a background click generates a privateClicked signal. Let’s disable it by adding 2 lines into Dialog’s creation:

  1.     signal privateClicked
  2.     onPrivateClicked: {}

and we get truly modal dialog.

Full example of page with dialog

  1. import QtQuick 1.1
  2. import com.nokia.meego 1.0
  3.  
  4. Page {
  5.  
  6. QueryDialog {
  7.     id: quDialog
  8.     signal privateClicked
  9.     onPrivateClicked: {}
  10.     anchors.centerIn: parent
  11.     titleText: "Modal Dialog"
  12.     rejectButtonText: "Cancel"
  13.     onRejected: { console.log ("Rejected");}
  14.   }
  15.   Component.onCompleted: quDialog.open()
  16. }

Categories: