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
babakar
Posts: 770
Registered: ‎05-29-2012
My Device: see later
Accepted Solution

benefit of property variant

Whats the benefit of this

when i use it insive navpane, and define everywhere  navPane.myspecialcolor

 

instead of creating it everywhere?

 

 

property variant mySpecialColor: Color.create("#fffffcf6")

Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: benefit of property variant

Less memory used, less objects created (faster loading of screens). The code is easier to understand.

 

I usually keep all styles such as colors / fonts etc in a separate object.
Such as:

 

Style.qml

QtObject {
  id: style

  property variant colorAaa: Color.create(…)
}

 

This way when you need to change the color of labels or other style properties, only one place needs to be changed.


Andrey Fidrya, @zmeyc on twitter
Developer
babakar
Posts: 770
Registered: ‎05-29-2012
My Device: see later

Re: benefit of property variant

okey , so I do one style .qml

then in my code i say style.colorAaa right?

less memory used, right. thanks for information.
Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: benefit of property variant

Right. It needs to be instantiated somewhere.

For example, in main.qml:

 

Page {


  attachedObjects: [
    MyAppStyle {
      id: appStyle
    }
  ]
}

Then use appStyle.propertyName in child items. 

 


Andrey Fidrya, @zmeyc on twitter
Developer
babakar
Posts: 770
Registered: ‎05-29-2012
My Device: see later

Re: benefit of property variant

Thanks alot, I have defined this already because am using it alot of places

 

import QtQuick 1.0


QtObject 
{
		    property variant lightGray: Color.LightGray
		    property variant white: Color.White
		    property variant black: Color.Black
            property variant subtitleText: SystemDefaults.TextStyles.SubtitleText
            property variant titleText: SystemDefaults.TextStyles.TitleText
}

 

Developer
greenmr
Posts: 919
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: benefit of property variant

You can also attach anything for which you want global access the the Qt object:

 

Page{
   id: myMainPage
   ComponentDefinition {
      id: styleDef
      MyAppStyle {
      }
   }
   onCreationCompleted: {
      Qt.myAppStyle = styleDef.createObject();
   }
}

...or if you'd rather just attach it to the main page so it gets destroyed automatically:

 

Page{
   id: myMainPage
   attachedObjects: [
      MyAppStyle {
         id: appStyle
      }
   ]
   onCreationCompleted: {
      Qt.myAppStyle = appStyle;
   }
}

 

Now you can access your style class from ANY QML in your app without additional declarations or "using" statements. Just always refer to it as Qt.myAppStyle.

 

The Qt object is always present and globally accessible from any QML file, and you can store not only objects, but also functions on it. Something like this perhaps:

 

Qt.myFunc = function() {
   // ---This function will be globally accessible in any QML file.
}

Although generally frowned up, for good reason, there are times when making something global is the sensible way to go.


Zmey wrote:

Right. It needs to be instantiated somewhere.

For example, in main.qml:

 

Page {


  attachedObjects: [
    MyAppStyle {
      id: appStyle
    }
  ]
}

Then use appStyle.propertyName in child items. 

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.