qt - Set Button imageSource from imageprovider -
i have image provider derived qquickimageprovider implementation of requestpixmap.
this image provider works fine image component.
now want provide imagesource button in same way. no image shows up. can problem?
qml code
image { anchors.fill: parent anchors.margins: 10 source: "image://provider/" + model.displayrole fillmode: image.preserveaspectfit } button { layout.fillwidth: true layout.preferredheight: width iconsource: "image://provider/" + model.displayrole onclicked: appcore.switch(model.displayrole) } c++ code
qpixmap imageprovider::requestpixmap(const qstring &id, qsize *size, const qsize &requestedsize) { qmodelindex index; bool foundid = false; for(int row = 0; row < m_mymodel->rowcount(); row++) { index = m_mymodel->index(row, 0); qstring name = qvariant(m_mymodel->data(index, qt::displayrole)).tostring(); if(name == id) { foundid = true; break; } } if(!foundid) return qpixmap(); qicon icon = m_mymodel->data(index, qt::decorationrole).value<qicon>(); qpixmap pixmap = icon.pixmap(128,128); return pixmap;; }
Comments
Post a Comment