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
Posts: 783
Registered: ‎05-29-2012
My Device: see later
My Carrier: 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
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

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
Posts: 783
Registered: ‎05-29-2012
My Device: see later
My Carrier: 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
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

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
Posts: 783
Registered: ‎05-29-2012
My Device: see later
My Carrier: 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
Posts: 1,004
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

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.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.