2

This is a question about good coding practice with QML:

How can I make sure that a Row {} or Column {} does not contract when one of its Item's visible: property is set to false?

The current work around is poor in that I set the height of the item to 0.0001.

1

I you need to keep the column size, do not use the visible property, prefer to set the Item opacity to 0:

Example:

import QtQuick 2.0

Rectangle {
    width: 200
    height: 200

    Column { /* outer column */
      spacing: 10
      Text { text: "Column Element"}
      Column { /* inner column */
        x: 10; y: 10
        spacing: 10
        Rectangle { width: 40; height: 20; color: "red" }
        Rectangle { width: 40; height: 20; color: "green" }
        Rectangle { width: 40; height: 20; color: "blue"; opacity: 0 }
      }
      Text { text: "Row Element" }
      Row { /* inner row */
        spacing: 10
        Rectangle { width: 40; height: 20; color: "red" }
        Rectangle { width: 40; height: 20; color: "green" }
        Rectangle { width: 40; height: 20; color: "blue" }
      }
    }
}

Result:

enter image description here

  • Unfortunately in this case; this is not an acceptable solution, as the components visibility will block anything under it from being interacted with. In this case; a flickable. :P – Akiva Sep 23 '14 at 11:18
  • @Akiva Humm, difficult to figure out what you're trying to achieve here. Could you include the relevant part (including the Flickable) in your question please? – Sylvain Pineau Sep 23 '14 at 11:35
  • yah sure i.imgur.com/GCsBfma.jpg -- see how these buttons are situated above the flickable here? If I make it transparent, then the flickable can not be flicked if I click on the relavent area. – Akiva Sep 23 '14 at 11:50
  • What we ended up doing is getting rid of the row, and setting the x manually, although that code was not the prettiest either. – Akiva Sep 23 '14 at 13:37
  • @Akiva: Could you give us the bzr branch you're working on please? that way we could try other "prettier workarounds" – Sylvain Pineau Sep 23 '14 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.