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 Knowledge Base

How to compile resources and use them for any device

by Developer on ‎10-29-2013 01:37 PM (1,558 Views)

Symptoms

Quote:

Static asset selection is not supported with compiled resources. For example, if your app stores QML assets in a 720x720 folder, you can't compile your QML resources.

Diagnosis

As I quoted above, you can not compile resources and use asset selection for different devices (resolution).

Solution

Link bbdevice library

#your pro (project qt) file
LIBS += -lbbdevice

 

Include DisplayInfo class

#include <bb/device/DisplayInfo>

using namespace bb::device;

Create a QML property in your ApplicationUI class . I call it fullTouch. This means that is not 720x720 device.

Q_PROPERTY(bool fullTouch READ fullTouch WRITE setFullTouch NOTIFY fullTouchChanged)

4.Then set this property before you load qml ui

DisplayInfo display;
int width = display.pixelSize().width()
int height = display.pixelSize().height();
if (width == 720 && height == 720){
setFullTouch(false);
}else{
setFullTouch(true);
}

3. Expose it to QML

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this).property("_App", this)

4. Use it

ImageView{
    // some properties
    imageSource: _App.fullTouch ? "asset:///Images/fullTouchImage.png" : "asset:///Images/720x720image.png"
}
Users Online
Currently online: 22 members 5,725 guests
Please welcome our newest community members: