Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)
Accepted Solution

Problem displaying images in a ListView

Hi everybody,

 

I am trying to displaying images in a grid (GridListLayout) in a ListView component (like this example). However it just displays the paths of the images I am trying to display (take a look at attachment 1 if this is unclear to you). What am I doing wrong?

 

In my data model you can find this data method:

 

QVariant ComicsDataModel::data(const QVariantList& indexPath)
{
	return QVariant("assets/images/legodude.jpg");
//return coverList.at(indexPath[0].toInt());
}

The commented code returns the actual filepaths (absolute paths), but that doesn't work either. I obviously included the image in the assets/images folder. The ListView is specified as written below.

 

            ListView {
                objectName: "coverListView"
                layout: GridListLayout {}
 
			    listItemComponents: [
			        ListItemComponent {
			            type: "image"
			 
			            ImageView {
			                imageSource: ListItemData
			                scalingMethod: ScalingMethod.AspectFill
			            }
			        }
			    ]
            }

 Thanks for the help! All the examples working with images use XML as datamodel, I use a custom data model.

 

Attachment 1:IMG_00000016.png

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
ekke
Posts: 1,566
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: Problem displaying images in a ListView

try this:

 

"../images/legodude.jpg"

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Problem displaying images in a ListView

No luck, still displays the string instead of the image. Could it be a problem that I am passing a QString in a QVariant object?

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Problem displaying images in a ListView

Some other stuff I tried already:

 

QVariant ComicsDataModel::data(const QVariantList& indexPath)
{
	return QVariant("asset:///images/legodude.jpg");
}

 

QVariant ComicsDataModel::data(const QVariantList& indexPath)
{
	return QVariant(QUrl("asset:///images/legodude.jpg"));
}

 Still no luck.

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Developer
strobejb
Posts: 282
Registered: ‎10-15-2012
My Device: bb10 developer

Re: Problem displaying images in a ListView

Probably your custom datamodel is not correctly returning the correct values in the DataModel::itemType() function - make sure you are returning "image" appropriately in your overload of itemType() - or use the equivalent ListView callback function in QML 

Developer
zezke
Posts: 1,004
Registered: ‎12-12-2010
My Device: Z10 (red Limited Edition)

Re: Problem displaying images in a ListView

You sir are very kind, thanks a lot! I totally forgot overwriting that method.

 

QString ComicsDataModel::itemType(const QVariantList& indexPath)
{
	return "image";
}

 

-------------------------------------------
BlackBerry Certified Builder for Native Application Development -- Proud member of the Belgian BlackBerry Developer group
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!