[solved] Custom dialog
-
Hello,
well i would go ahead and create a new Window in for example myCustomDialog.qml. You can design the Window for your purposes. From you main QML you just create it as a new component and show it.
@var component = Qt.createComponent("myCustomDialog.qml");
dialog = component.createObject(root);
dialog.show();@
I would add some signals to your dialog, for example yes, no, whateveryouwant,... and then catch the emit of them with dialog.onYes, ... .Havn't tested it out but it should work :)
For futher information:
"Window":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick-window2-window.html -
Looking in the source code of Qt, I've created this example:
@
import QtQuick 2.0
import QtQuick.Dialogs 1.1
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1Rectangle {
AbstractMessageDialog { id: dialog title: "Error message" ColumnLayout { anchors.fill: parent Text { text: "Text of sample" } Button { text: "close" onClicked: { dialog.close(); } } } } Button { text: "Show dialog" onClicked: dialog.open(); // Same as dialog.visible = true; }
}
@In the header file of AbstractMessageDialog, it is commented that the file is not part of Qt interface and that it could could be removed.
-
And another sample, based on window:
@
import QtQuick 2.0
import QtQuick.Controls 1.1
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0Rectangle {
width: 400
height: 400Window { id: win_dialog flags: Qt.Dialog title: "Error message" modality: Qt.ApplicationModal ColumnLayout { anchors.fill: parent Text { text: "Text of sample" } Button { text: "close" onClicked: { win_dialog.visible = false; } } } visible: false } Button { text: "Show dialog" onClicked: win_dialog.visible = true; }
}
@