Welcome to the Official BlackBerry Support Community Forums.


inside custom component

Native Development

Posts: 95
Registered: ‎10-19-2010
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


Please use plain text.
Posts: 6,445
Registered: ‎12-08-2010
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...

Please use plain text.
Posts: 174
Registered: ‎03-05-2009
My Carrier: -

Re: Reuse TextStyleDefinition

use the Qt global object:


onCreationCompleted: {

  Qt.myTextStyle = myTextStyle



attachedObject: [

 TextStyleDefinition {

    id: myTextStyle




Please use plain text.
Posts: 399
Registered: ‎06-03-2010
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, ....

Please use plain text.