10-03-2012 08:53 AM
Ah yes... you are correct - here's another post on from their site, confirming what you are saying...
http://devblog.blackberry.com/2012/08/blackberry-1
Chris
10-08-2012 02:47 PM
TheRain wrote:Hi guys, appologies if this has been answered elsewhere, or if there is another better solution for this. The solution I'm using is to get DisplayInfo via C++, grab the screen dimensions from that, and pass them in to my QML document. Here's how to do that:
C++ Code:
#include <bb/device/DisplayInfo> using namespace bb::device;
QmlDocument *qml = QmlDocument::create("asset:///main.qml"); qml->setParent(this); DisplayInfo display; int width = display.pixelSize().width(); int height = display.pixelSize().height(); QDeclarativePropertyMap* displayProperties = new QDeclarativePropertyMap; displayProperties->insert("width", QVariant(width)); displayProperties->insert("height", QVariant(height)); qml->setContextProperty("DisplayInfo", displayProperties);Now a DisplayInfo object is accessible from QML like so:
ImageView{ imageSource: "asset:///images/my_awesome_full_screen_image.png" preferredHeight: DisplayInfo.height preferredWidth: DisplayInfo.width scalingMethod: ScalingMethod.AspectFill }
And don't forget to add LIBS += -lbbdevice in the .pro file ![]()
10-08-2012 06:27 PM
that is an awful lot of code to write, just in order to get the screen height...
10-08-2012 06:36 PM
Exposing anything in QML that's not already exposed will take at least a similar amount of code. I think it's likely some method will be added to Cascades to do this that won't require C++ in the future- if it's not already there and simply undocumented.
I heard a few complaints while at BB Jam about code examples having hard coded screen size values- I think it will likely be addressed eventually.
10-08-2012 06:40 PM
I was one of the people making those complains. Simply passing display info values like this isn't really a good solution either. What we need is a way of doing property binding like everything else in QML, so that anything affected by those values will automatically update when they change. (and they can change, due to rotation and sometimes virtual keyboard display)
Oh, and it should be built in, and referenced from any and all examples that have a reason to care.
10-08-2012 07:00 PM
10-08-2012 08:44 PM
I take it nobody here has noticed the LayoutUpdateHandler yet?
import bb.cascades 1.0
Page {
Container {
Label {
id: theLabel
}
attachedObjects: LayoutUpdateHandler {
onLayoutFrameChanged: {
theLabel.text = 'size ' + layoutFrame.width + " x " +
layoutFrame.height;
}
}
}
}
Imagine a screenshot that reads: "size 768 x 1280" posted here...
10-08-2012 10:53 PM
Also the above code will work for me once you touch the element, but instead displays '0' when you launch the app...
import bb.cascades 1.0 NavigationPane { id: navigationPane Page { id: mainPage Container { layout: DockLayout {} attachedObjects: [ LayoutUpdateHandler { id: layout } ] Label { id: textLabel setTextLabel() onTouch: { setTextLabel() } function setTextLabel() { textLabel.text = handler.layoutFrame.width } } } }
10-08-2012 11:07 PM
10-09-2012 01:41 PM
peter9477 wrote:I take it nobody here has noticed the LayoutUpdateHandler yet?
import bb.cascades 1.0 Page { Container { Label { id: theLabel } attachedObjects: LayoutUpdateHandler { onLayoutFrameChanged: { theLabel.text = 'size ' + layoutFrame.width + " x " + layoutFrame.height; } } } }
Imagine a screenshot that reads: "size 768 x 1280" posted here...
I think this is actually the best solution/hack until we get (maybe) some updates from BB