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: 127
Registered: ‎07-02-2013
My Device: Q10 v10.3.1.1565
My Carrier: {unbranded}
Accepted Solution

how to get resolution

is there an elegant way to get resolution of the device? i know there are just 3 resolutions at all, there are asset folders for each resolution, but i would like to get screen size to calc it's ratio.

 

i couldn't find anywhere in docs and the only solution which comes to me is a workaround by reading w/h of sullscreen contener.

 

thanks.

Developer
Posts: 120
Registered: ‎03-13-2012
My Device: Playbook, Dev Alpha C, Q10, Z10, Z30
My Carrier: T-Mobile

Re: how to get resolution

[ Edited ]

I use:

 

int rect[4] = { 0, 0, 0, 0 };

 

screen_context_t screen_ctx;

screen_window_t screen_win;

 

screen_create_context(&screen_ctx, 0);

screen_create_window(&screen_win, screen_ctx);

screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, rect+2);

 

rect[2] is pixels in the x direction.

rect[3] is pixels in the y direction.

 

rect[0] and [1] are 0.

 

Don't know about Cascades.

Developer
Posts: 127
Registered: ‎07-02-2013
My Device: Q10 v10.3.1.1565
My Carrier: {unbranded}

Re: how to get resolution

[ Edited ]

actually i use QML/Cascades - i didn't mention.

so i don't create screen in that manner :/

Highlighted
Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: how to get resolution

[ Edited ]

It's only fair I help you with this one since your suggestion allowed me figure out how to detect WiFi connection status. 

 

 

bb::device::DisplayInfo display;
int width = display.pixelSize().width();
int height = display.pixelSize().height();

Note that pixelSize.width() and pixelSize.height() are NOT static functions so you need an actual instance of DisplayInfo for this to work. If you want to make the dimensions available in QML do this in your main UI class constructor...

 

bb::device::DisplayInfo display;
QDeclarativePropertyMap* displayDimensions = new QDeclarativePropertyMap;
displayDimensions->insert( "width", QVariant( display.pixelSize().width() ) );
displayDimensions->insert( "height", QVariant( display.pixelSize().height() ) );
qml->setContextProperty( "DisplayInfo", displayDimensions );

...then you can use DisplayInfo.width and DisplayInfo.height in your QML and JavaScript.



Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 16,998
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to get resolution

you can also use an UpdateLayoutHandler in QML.
Note that it gives you the available space for the component it is registered for, but sometimes that is what you want.
(for example if you have a title bar and a field at the bottom)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 127
Registered: ‎07-02-2013
My Device: Q10 v10.3.1.1565
My Carrier: {unbranded}

Re: how to get resolution

[ Edited ]

thanx for this one,

i will test it later.

 

EDIT:

and for second one thanx too. it may work perfectly for me, as i need it for fullscreen camera component

Developer
Posts: 1,168
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: how to get resolution

Yep, I've used that in a few places when I needed to make one control resize to match another, but in this case the OP specfically asked how to find physical screen dimensions, unless I misunderstood.

 

 


simon_hain wrote:
you can also use an UpdateLayoutHandler in QML.
Note that it gives you the available space for the component it is registered for, but sometimes that is what you want.
(for example if you have a title bar and a field at the bottom)





Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 127
Registered: ‎07-02-2013
My Device: Q10 v10.3.1.1565
My Carrier: {unbranded}

Re: how to get resolution

your understanding was perfectly fine. i need to calculate screen w/h ration for fullscreen component, so the second solution would work too