// // in the our TreeView implementation BaseTreeView.qml // TreeView { id: root property Component itemDelegateIcon // ... itemDelegate: Item { id: itemDelegateContent // ... Loader { id: nodeIcon anchors.verticalCenter : parent.verticalCenter anchors.left: parent.left sourceComponent: root.itemDelegateIcon } } // ... } // // In the application TreeView implementation DirectoryTreeView.qml // BaseTreeView { // ... /// /// Icon for directories /// itemDelegateIcon: Component { Item { anchors.fill: parent Image { anchors.bottom: parent.bottom anchors.right: parent.right height: 12 width: 14 source: "images://OSFileIconImageProvider/" + root.GetPath(index); } } } // ... } // // In the custom QQuickImageProvider FileIconImageProvider.cpp // // ... QPixmap FileIconImageProvider::requestPixmap( const QString &id, QSize *size, const QSize &requestedSize ) { // The requestedSize here is correct on start up of the application. requestedSize = (12,14) // However, if I expand a tree node // to make the nodes below the expanded one out of view, when I collapse the expanded node and bring // those nodes into view, the icon size is changed. If the value of requestedSize here is changed: // requestedSize = (12,14) * screen_scale_factor from another screen // Create the QFileInfo for the given path QFileInfo file_info( id ); // Get the icon for the given QFileInfo QIcon icon = mIconProvider->icon( file_info ); const int width = requestedSize.width() > 0 ? requestedSize.width() : mDefaultWidth; const int height = requestedSize.height() > 0 ? requestedSize.height() : mDefaultHeight; // Get the QPixmap from the icon QPixmap pixmap = icon.pixmap( width, height ); const int pixmap_width = pixmap.width(); const int pixmap_height = pixmap.height(); if( size ) { *size = QSize( pixmap_width, pixmap_height ); } // Scale the pixmap to the requested size return pixmap.scaled( width, height ); }