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: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All
Accepted Solution

How to get the screen dimension in QML?

Is there a way to get the width and height of the current screen in QML?

 

Because I have to use the absolute layout and I also want to let the position of controller could fit with different dimension of screens, I plan to calculate the position based on the screen size to locate the controller to a relative position. In BB7 development, it is availabe to do this way. But I have not found how to realize it in BB10 QML.

 

Thank you someone can figure it out.




p(^_^)q
Good good study, day day up
Highlighted
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to get the screen dimension in QML?

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: How to get the screen dimension in QML?

[ Edited ]

Another option is to attach LayoutUpdateHandler to a container and reposition controls on updates. This way screen rotation won't break the layout.

 

https://developer.blackberry.com/cascades/reference/bb__cascades__layoutupdatehandler.html

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All

Re: How to get the screen dimension in QML?

Both your answers are so great. I got it. Thank you.




p(^_^)q
Good good study, day day up
Developer
Posts: 313
Registered: ‎05-31-2010
My Device: Alpha 10, Bold 9900, Storm 9530, Tour 9630, Curve 9320, Curve 8900
My Carrier: All

Re: How to get the screen dimension in QML?

LayoutUpdateHandler is very useful. I can finally realize the complicated UI by that. If this methodology could be mentioned in the official documentation, i think that it will help the developers a lot.




p(^_^)q
Good good study, day day up
Developer
Posts: 71
Registered: ‎09-19-2012
My Device: Z10 very soon
My Carrier: Play

Re: How to get the screen dimension in QML?

very simple example Smiley Happy.  

 

 

import bb.cascades 1.0

Page {
   Container {
       id: rootContainer
       attachedObjects: [
           LayoutUpdateHandler {
               id: layoutHandler
           }
       ]
  Label {
      text: layoutHandler.layoutFrame.width
    }
  }
}