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
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings
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
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
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 native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

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
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

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
Posts: 293
Registered: ‎10-15-2012
My Device: bb10 developer
My Carrier: Orange

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 

Highlighted
Developer
Posts: 1,008
Registered: ‎12-12-2010
My Device: Passport (Red Limited Edition)
My Carrier: Mobile Vikings

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!