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
New Contributor
Posts: 3
Registered: ‎07-16-2013
My Device: Z10
My Carrier: MTel

How to get Label's width in pixels

I am trying to get the width in pixels of Label after setting the text and before make it visible in the Container. I need this in order to center the label onto an image. I tried LayoutUpdateHandler but it does not work before the control is added and showed in the Container. Is there a way to get the size before the control is showed in the Container?

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to get Label's width in pixels

so far i think not. we have a feature request on jira regarding this topic iirc.
----------------------------------------------------------
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
Regular Contributor
Posts: 94
Registered: ‎12-02-2011
My Device: non-Blackberry user
My Carrier: none

Re: How to get Label's width in pixels

It would be nice if Cascade offered us the QFont and QFontMetrics class

Developer
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10
My Carrier: MTS

Re: How to get Label's width in pixels

I haven't found any solution except mentioned LayoutUpdateHandler.
Why don't you use layouts to align label?
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
New Contributor
Posts: 3
Registered: ‎07-16-2013
My Device: Z10
My Carrier: MTel

Re: How to get Label's width in pixels

"Why don't you use layouts to align label?"

 

Yes, I did it using DockLayout. My question was of principle if there is such an API. Thank you all Smiley Happy