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. Visible property usage
Forum Updated to NodeBB v4.3 + New Features

Visible property usage

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 2.4k 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.
  • J Offline
    J Offline
    Julie1986
    wrote on last edited by
    #1

    Hello, I have 5 devices on the main screen. Each time I display one device I have to make the other 4 visible:false. I do it in this way as I am new to qml

    device1.visible:true
    device2.visible:false
    device3.visible:false
    device4.visible:false
    device5.visible:false

    . Instead of doing this everywhere is there any short method to implement this. Thanks for your time.

    Alternatively i also thought of using-- propery bool view:false and then assigning it to other device but this would also take many lines of code. I want to do it with min. LOC

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

      Would that be OK?
      @
      property int visibilityFlag: 0x10000;

      device1.visible: (visibilityFlag & 0x10000)? true: false;
      device2.visible: (visibilityFlag & 0x01000)? true: false;
      device3.visible: (visibilityFlag & 0x00100)? true: false;
      device4.visible: (visibilityFlag & 0x00010)? true: false;
      device5.visible: (visibilityFlag & 0x00001)? true: false;
      @

      Warning: not tested. Use at your own responsibility. :)

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        godbod
        wrote on last edited by
        #3

        Hello

        This problem makes me think about ListView, ListModel and Component. You could have been able to set a default property to false for the delegate. Then, each time you click on an Item, you set it to true with :
        @
        device.visible : Element.isCurrentItem? true : false /Element is ListView for instance/
        @

        Sierdzio solution is logic though...This kind of problem usually has a n complexity solution.

        Why not create a x elements listView to represent your x elements devices then each time you click on the corresponding element device in the listview, you retrieve the status of each variable :) ? That's straightforward

        L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

        1 Reply Last reply
        0
        • F Offline
          F Offline
          favoritas37
          wrote on last edited by
          #4

          The correct solution for your case is the use of "States":http://doc.qt.digia.com/4.7-snapshot/qdeclarativestates.html. Define 5 States which describe the 5 different looks of your qml and just change the state whenever needed. So your code will look like this:

          @
          Rectangle{

          state: "device1Visible"
          
          device1.visible: state == "device1Visible"
          device2.visible: state == "device2Visible"
          device3.visible: state == "device3Visible"
          device4.visible: state == "device4Visible"
          device5.visible: state == "device5Visible"
          
          states:[
              State{ name: "none"},
              State{ name: "device1Visible" },
              State{ name: "device2Visible" },
              State{ name: "device3Visible" },
              State{ name: "device4Visible" },
              State{ name: "device5Visible" }
          ]
          

          }
          @

          Of course in this case it could be done using a simple string but the use of States can give you more.

          PS: I know it is not the most compact way of writing this so probably it doesn't answer your exact question but in my opinion this is how it should be done that is why i mention it.

          Regards.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Julie1986
            wrote on last edited by
            #5

            Thank you all for your suggestion.:)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              godbod
              wrote on last edited by
              #6

              Feel free to ask more questions if you want. ;)

              L'imagination est tout, c'est l’aperçu des futures attractions de la vie.

              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