I have a private library returning a QFrame. The GUI of my program is developed with QML (Qt Quick 2.0). I need a solution to integrate QFrame (QWidget) in QML
Note: I found an example: Qt_DIR / Examples / Qt-5.3 / declarative / cppextensions / qwidgets that do something that I need. In this example, QWidged is added to the QGraphicsProxyWidget. I write my code like this, but when I run the application, it shows me in the console: "It is impossible to add QtQuick 1.0 (MyPushButton) to the QtQuick 2.0 scene." This is the 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; };
source share