Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it better to create new QML items if I use the same default properties?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    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
    }
    @

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aabc
        wrote on last edited by
        #3

        Thanks sierdzio.
        And what is better for performance ?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aabc
            wrote on last edited by
            #5

            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 ?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [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.

              (Z(:^

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved