Is it better to create new QML items if I use the same default properties?



  • In my application I want to use the QMl Text element in many places with the same properties (for example color: "black", horizontalAlignment: Text.AlignHCenter etc.).
    Is it better to create my own Text element in a new QML file and set these properties ?

    For example:
    MyText.qml

    @Text
    {
    color: "black"
    horizontalAlignment: Text.AlignHCenter
    elide: Text.ElideLeft
    }
    @


  • Moderators

    I think you are right, it is better to create your own component. This way, when you want to change anything, you only need to do it in one place, one file. Otherwise you would be forced to do this everywhere you use the Text element.



  • Thanks sierdzio.
    And what is better for performance ?


  • Moderators

    I doubt there would be any noticeable difference. Loading time can increase by the amount it takes to open and parse MyText.qml, but that is almost instantaneous. There should be no speed difference at runtime.



  • If I have 12 QML pages that loads dynamically, each page contain ~400 MyText elements - Do you think that in this case the pages will be loaded faster if I use the MyText element instead of using Text element and give it the properties ?


  • Moderators

    [quote author="aabc" date="1413206015"]If I have 12 QML pages that loads dynamically, each page contain ~400 MyText elements - Do you think that in this case the pages will be loaded faster if I use the MyText element instead of using Text element and give it the properties ?[/quote]

    Please benchmark it, I don't know. I guess the difference would not be substantial, but that is a guess.

    QML enigne provides a lot of flags that can be used in debugging. You can get in touch with QML developers (see maintainers list here on Qt Project website) to get more concrete answers. Or ask on Qt interest mailing list/ IRC.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.