Different delegates for QML ListView

I’ve had the same problem, the Qt documentation is providing a pretty good answer: http://doc.qt.io/qt-5/qml-qtquick-loader.html#using-a-loader-within-a-view-delegate The easiest solution is an inline Component with a Loader to set a source file: ListView { id: contactsView anchors.left: parent.left anchors.top: parent.top width: parent.width height: parent.height orientation: Qt.Vertical spacing: 10 model: contactsModel delegate: Component { Loader { source: switch(position) … Read more

QML and C++ image interoperability

It was possible to do in QtQuick1 but that functionality was removed in QtQuick2. The solution I’ve come up with allows to have the same image in QML and C++ by implementing a QQuickImageProvider that basically works with QPixmap * which is converted to string and then back to a pointer type(it does sound a … Read more

QML garbage collection deletes objects still in use

I’ve encountered this problem on several occasions, with objects created dynamically, regardless of whether they were created in QML or C++ Objects are only considered for garbage collection if they have JavaScriptOwnership set, which is the case if they are Directly created by JavaScript/QML Ownership is explicitly set to JavaScriptOwnership The object is returned from … Read more

declare global property in QML for other QML files

Use a QML Singleton. Please reference “Approach 2” on this page — The ugly QTBUG-34418 comments are mine. These are the pieces you need: Style.qml pragma Singleton import QtQuick 2.0 QtObject { property color mainbg: ‘red’ } qmldir This file must be in the same folder as the singleton .qml file (Style.qml in our example) … Read more

C++ signal to QML slot in Qt

You should use Connections in this case (maybe it’s the only way to connect). Put your object myObj to QML file by setContextProperty qmlVectorForm->rootContext()->setContextProperty(“YourObject”, myOb); Your signal is finishedGatheringDataForItem(QString signalString) In QML file, add Connectios likes below: Connections { target: YourObject onFinishedGatheringDataForItem: { qmlString = signalString } }

Qt5. Embed QWidget object in QML

Qt Quick 2 uses a scene graph for efficient rendering on the GPU. Unfortunately this makes it impossible to embed classic widgets into the scene. The old approach to embed such widgets with the help of QGraphicsProxyWidget works only with Qt Quick 1, because internally it uses a QGraphicsView for all the heavy lifting and … Read more