c++ - QML and QQuickImageProvider size -
i have writen qml application shows qimages image provider. wrote class inherits qquickimageprovider. in qml have 2 image objects.
columnlayout { rowlayout { image { source: "image://backend/1" width: parent.width/2 } image { source: "image://backend/1" width: parent.width/2 }
and code of provider:
qimage qmlprovider::requestimage(const qstring &id, qsize *size, const qsize &requestedsize) { qsize req(requestedsize.width()<0?100:requestedsize.width(), requestedsize.height()<0?100:requestedsize.height()); try { qimage ret=assign.at(id)->scaled(req,qt::keepaspectratio); *size=ret.size(); return ret; } catch( out_of_range ) { qimage ret(req,qimage::format_rgb16); *size=ret.size(); ret.fill(qcolor(qrand()/(rand_max/255),qrand()/(rand_max/255),qrand()/(rand_max/255)).rgba()); return ret; } }
it works far means picture ist shown. want these pictures scaled. want each picture fill 1 half of application window, doesn't work. each width set ignored , image provider every time invalid requested size.
what have achive this?
since item's size managed layout
should set layout's preferred size instead of item's size:
rowlayout { anchors.fill: parent image { source: "image://backend/1" layout.preferredheight: parent.height layout.preferredwidth: parent.width / 2 } image { source: "image://backend/1" layout.preferredheight: parent.height layout.preferredwidth: parent.width / 2 } }
more info found here
Comments
Post a Comment