简体   繁体   中英

Insert QTreeWidget into QQuickWindow child element

I'd like to insert a QTreeWidget into my top level QQuickWindow. Is it possible? The code below is commented to show my general idea.

IDEA.CPP

....
//in main somewhere
QTreeWidget *tree = new QTreeWidget();

//Magically insert tree into window
....

main.cpp

int main(int argc, char *argv[])
{

    QApplication app(argc, argv);
    QQmlApplicationEngine engine;

    qmlRegisterType<Data>();


    engine.rootContext()->setContextProperty("classInstance", new polysync_api_wrapper);
    engine.rootContext()->setContextProperty("trace", new Trace);

    engine.load(QUrl("qml/main.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

    window->show();

    return app.exec();
}

main.qml

ApplicationWindow {

    ......
    Rectangle {
        id: treeWindowContainer
        ....

        --->**TREE WIDGET GOES HERE PLZ!?   SUCH AMAZE!!!**<---
        ....
    }

}

Thanks all! All somewhat decent suggestions get upvotes !!! It's Friday !!!

You need an item that wraps a QWidget . There's no such item, but the closest you get is QQuickPaintedItem . You'd need to derive from it and write an item that can take an instance of QWidget and use its render method to paint the item. There's also work to be done on forwarding the events between the two.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM