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
maarko
Posts: 119
Registered: ‎07-02-2013
My Device: Q10 v10.2.0.424
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
mmd12
Posts: 117
Registered: ‎03-13-2012
My Device: Playbook, Dev Alpha C, Q10, Z10

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
maarko
Posts: 119
Registered: ‎07-02-2013
My Device: Q10 v10.2.0.424

Re: how to get resolution

[ Edited ]

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

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

Developer
greenmr
Posts: 919
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

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. 

 

:Angel:

 

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.
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

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
maarko
Posts: 119
Registered: ‎07-02-2013
My Device: Q10 v10.2.0.424

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
greenmr
Posts: 919
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

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.

 

:Sweatdrop:

 


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.
Developer
maarko
Posts: 119
Registered: ‎07-02-2013
My Device: Q10 v10.2.0.424

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