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. Singleton Item
Forum Updated to NodeBB v4.3 + New Features

Singleton Item

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 2.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.
  • V Offline
    V Offline
    vulee
    wrote on last edited by
    #1

    Is it possible to have just an instance of visual item (singleton Rectangle) for the whole app? For example my app has 4 rectangles, each of these rectangle contains the same singleton Rectangle.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludde
      wrote on last edited by
      #2

      Don't think that's possible. If they were all the same instance, they would have to share the same property values, e.g. for x and y, and that would be kind of useless, wouldn't it? I'm sure there are plenty of other reasons too, this was just the first one I thought of.

      Why do you want to do this? I'm sure there are other ways to accomplish what you are trying to do.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vulee
        wrote on last edited by
        #3

        This singleton object is (a) expensive to create and (b) compose of many components some of which are created on demand (that's why I intend not to have more than one). x and y could be modified to specify the position, but the width and height are fixed.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          The nature of a singleton is that there is only one of them in existence. If you have multiples of it on screen, then -- by definition -- it can't be a singleton.

          You can't have "visual clones" of an object itself. The closest I can think of is if you do some magic by rendering an image of the master object to a pixmap and just use copies of that pixmap in the other locations.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vulee
            wrote on last edited by
            #5

            You're right. It is not a singleton object... rather it is a flyweight object which is backed by a singleton. Is it possible to implement it in QML?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              ludde
              wrote on last edited by
              #6

              What you can do is separate all the visual aspects of the item from the data. Then you can have several instances of the visual item all sharing the same data. If it's the data that is expensive to to create, this should be a suitable solution. If it's the visual item that is expensive to create, then I'm really wondering what that visual item does and how it is created...

              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