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

Posts: 95
Registered: ‎10-19-2010
My Device: Blackberry 8110
My Carrier: Generic
Accepted Solution

Reuse TextStyleDefinition



I'm using TextStyleDefinition in every QML to define the style of the labels I'm using.


The problem is that I want to use those TextStyleDefinition in more than one QML, I want to reuse them because those styles I'm defining are used across the application. I've been trying to create a QML just for TextStyles but I can't get it to work using attachedObjects.


How can I achieve this? Basically I want to create TextStyles that can be used in every QML(Pages or Sheets).


Thank you very much indeed


Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Reuse TextStyleDefinition

I would think you could attach those to your root QML component which, if you labelled it with "id: root" as many do, would let you access them from almost anywhere using "root.myStyleA.style" or something close to that. I haven't tested that exactly as described...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Reuse TextStyleDefinition

use the Qt global object:


onCreationCompleted: {

  Qt.myTextStyle = myTextStyle



attachedObject: [

 TextStyleDefinition {

    id: myTextStyle




Posts: 410
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: Reuse TextStyleDefinition

I have chosen the same method as lew, and it works pretty well.


It can be extended to other global variable to access: device-width, backgrounds and focus colors that you'll need again and again, ....