Birdfriender
Birdfriender

Reputation: 393

Creating a pop-up dialog in QtQuick 1.1

I am trying to implement a pop-up confirmation box in an application using QtQuick 1.1, this means I dont have access to QtQuick Dialogs. How would I go about implementing this? I couldn't find anything in the documentation

Upvotes: 1

Views: 433

Answers (1)

Leben Asa
Leben Asa

Reputation: 317

You can render your QML application unto QWidget, register this widget as context object, and expose static methods of QMessageBox to generate a dialog:

class QmlWidget : public QQuickWidget // or QWidget + QQuickView combination
{
...
public:
    void warning(const QString& title, const QString& message, ...)
    {
        QMessageBox::warning(this, title, message, ...);
    }
};

int main()
{
    QmlWidget w;
    auto engine = w.engine();
    auto ctx = engine.rootContext();
    // expose w to qml
    ctx->setContextProperty("qmlwidget", &w);
    w.show();
    return app.exec();
}

In QML:

Item {
    Component.onCompleted: qmlwidget.warning()
}

Or you can simply write a screen blocking Rectangle with Text items and buttons. Or simply upgrade your application into QtQuick 2.x!

Upvotes: 4

Related Questions