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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


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
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: How to get the screen dimension in QML?

Highlighted
Developer
Posts: 1,524
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
    }
  }
}