MessageDialog on iOS
-
I'd like show messagebox on iOS app. But unfortunately there is no native look dialogs for iOS. I could use MessageDialogs but they look bad and are in full screen size (tested on Qt 5.3.1). Is there existing native dialogs (or coming) or should I use custom dialogs? If so, what is the best way to do it?
-
On iOS you can mix very easily object-C with C++ code, and then, you can easily create a QObject subclass with a slot implemented in object-c on which you can create a iOS native message dialog and emit a signal on the delegate methods of native message dialogs.
I used this technique for showing UIAlertViews. I didn't try with UIActionSheet and UIActivityIndicator, but it should be easy.Otherwise, in another app, I created a custom dialogs. For doing so, I just created a full screen QML item with a semi-transparent gray rectangle filling the screen with a MouseArea catching any touches (in this way the dialogs behaves as a modal dialog) and adding to the center an item with the necessary graphics items for display the message and the buttons as the designer created them.
You can decide if to create this item on-fly every time with Qt.createComponent when you need, or you can create a single global instance to setup and make visible every time you need. -
[quote author="Gianluca" date="1404026975"]On iOS you can mix very easily object-C with C++ code, and then, you can easily create a QObject subclass with a slot implemented in object-c on which you can create a iOS native message dialog and emit a signal on the delegate methods of native message dialogs.
I used this technique for showing UIAlertViews. I didn't try with UIActionSheet and UIActivityIndicator, but it should be easy.Otherwise, in another app, I created a custom dialogs. For doing so, I just created a full screen QML item with a semi-transparent gray rectangle filling the screen with a MouseArea catching any touches (in this way the dialogs behaves as a modal dialog) and adding to the center an item with the necessary graphics items for display the message and the buttons as the designer created them.
You can decide if to create this item on-fly every time with Qt.createComponent when you need, or you can create a single global instance to setup and make visible every time you need.
[/quote]Hi Gianluca,
about your second solution (I want re-use the code also for Android), it was no more simple use the component "Dialog" for make a custom dialog in modality mode? Where is the convenience to make a custom rectangle ?
-
There has an example implementation of alert dialog for Android:
https://github.com/benlau/quickandroid/blob/master/tests/quickandroidexample/dialog/AlertDialog.qml
However, I think it is not a suggested method for iOS. Since the background mask of an iOS dialog will cover status bar . QML can not handle it. As it will not fulfill the requirement of app store , just afraid it will be banned.
-
[quote author="Tycos" date="1414748285"][quote author="Gianluca" date="1404026975"]On iOS you can mix very easily object-C with C++ code, and then, you can easily create a QObject subclass with a slot implemented in object-c on which you can create a iOS native message dialog and emit a signal on the delegate methods of native message dialogs.
I used this technique for showing UIAlertViews. I didn't try with UIActionSheet and UIActivityIndicator, but it should be easy.Otherwise, in another app, I created a custom dialogs. For doing so, I just created a full screen QML item with a semi-transparent gray rectangle filling the screen with a MouseArea catching any touches (in this way the dialogs behaves as a modal dialog) and adding to the center an item with the necessary graphics items for display the message and the buttons as the designer created them.
You can decide if to create this item on-fly every time with Qt.createComponent when you need, or you can create a single global instance to setup and make visible every time you need.
[/quote]Hi Gianluca,
about your second solution (I want re-use the code also for Android), it was no more simple use the component "Dialog" for make a custom dialog in modality mode? Where is the convenience to make a custom rectangle ?[/quote]
The convenience of make a custom rectangle depends on how much is the graphics of the dialog created by the designer. In the app I was referring on the reply, the designed created a very complex design of the dialog and for me was more easy to do with custom Items, instead of using the QtQuick Controls and customize the appearance via QtQuickControls.Styles.
-
On iOS you can mix very easily object-C with C++ code, and then, you can easily create a QObject subclass with a slot implemented in object-c on which you can create a iOS native message dialog and emit a signal on the delegate methods of native message dialogs.
I used this technique for showing UIAlertViews. I didn't try with UIActionSheet and UIActivityIndicator, but it should be easy.Otherwise, in another app, I created a custom dialogs. For doing so, I just created a full screen QML item with a semi-transparent gray rectangle filling the screen with a MouseArea catching any touches (in this way the dialogs behaves as a modal dialog) and adding to the center an item with the necessary graphics items for display the message and the buttons as the designer created them.
You can decide if to create this item on-fly every time with Qt.createComponent when you need, or you can create a single global instance to setup and make visible every time you need. -
@Gianluca Would it be possible to show how you did it? I'm not quite familiar with objective c so a sample code would be very helpful. Thank you!
-
-
@benlau Let me notify you of a possible error in qisystemmessenger.h. It contains this inclusion guard:
#ifndef QISYSTEMUTILS_H #define QISYSTEMUTILS_H
Which seems like a copy-paste error. BTW isn't it best to use
#pragma once
?
But thanks for your work. -
@benlau Let me notify you of a possible error in qisystemmessenger.h. It contains this inclusion guard:
#ifndef QISYSTEMUTILS_H #define QISYSTEMUTILS_H
Which seems like a copy-paste error. BTW isn't it best to use
#pragma once
?
But thanks for your work.@m_andrej Thanks for pointing out the problem. In fact, the mistake is not made by C&P. That is the original name of QISystemMessenger. Since the class is growthing, I have refactored the code to breakdown into multiple classes. But forgotten to rename the include guild.
"#pragma once" should be fine, I just use the default header file generator from Qt Creator.