8

I have closed library that return QFrame. GUI of my program is developed with QML (Qt Quick 2.0). I need solution to integrate QFrame (QWidget) to QML

Note: I found example: Qt_DIR/Examples/Qt-5.3/declarative/cppextensions/qwidgets, that do something as I need. In ths example QWidged is addeed to QGraphicsProxyWidget. I write my code like this, but when I run my aplication it show me in console: "Cannot add a QtQuick 1.0 item (MyPushButton) into a QtQuick 2.0 scene!". This is this code:

class MyPushButton : public QGraphicsProxyWidget
{
    Q_OBJECT
    Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)

public:
    MyPushButton(QGraphicsItem* parent = 0)
        : QGraphicsProxyWidget(parent)
    {
        widget = new QPushButton("MyPushButton");
        widget->setAttribute(Qt::WA_NoSystemBackground);
        setWidget(widget);

        QObject::connect(widget, SIGNAL(clicked(bool)), this, SIGNAL(clicked(bool)));
    }

    QString text() const
    {
        return widget->text();
    }

    void setText(const QString& text)
    {
        if (text != widget->text()) {
            widget->setText(text);
            emit textChanged();
        }
    }

Q_SIGNALS:
    void clicked(bool);
    void textChanged();

private:
    QPushButton *widget;
};


private:
    QPushButton *widget;
};
Andrew P.
  • 223
  • 2
  • 4
  • 11
  • Share some code, otherwise all answers are guesses. This also shows what you have done up to now and what the answers can rely/base up on. For your error description, i *guess* you have an import QtQuick 2.0 in your scene file header and QtQuick 1.0/1.1 in your form file header. Try "porting" your Form to QtQuick 2.0 – Sebastian Lange Jul 14 '14 at 11:44
  • Possible duplicate of [Qt5. Embed QWidget object in QML](http://stackoverflow.com/questions/13014415/qt5-embed-qwidget-object-in-qml) – Violet Giraffe Jul 27 '16 at 18:53

1 Answers1

2

QGraphicsProxyWidget is intended to use with QtQuick 1. Already there is answer Qt5. Embed QWidget object in QML

Another thought - you can embed your QWidget inside QQuickItem. Or look into QtQUickControls how they are painted with QtQuick2

Community
  • 1
  • 1
nib
  • 700
  • 8
  • 15