November 25, 2011

supaukko supaukko
Lab Rat
1 posts

[SOLVED] QML Column - how to prevent default functionality

 

Hi!

Is there a way to overwrite the default functionality when Column’s child goes fully transparent (no transitions)?

Here is an example code that describes the problem, hopefully (see removeBtn’s onClicked slot):

  1. import QtQuick 1.1
  2. Rectangle {
  3.     width: 360
  4.     height: 360
  5.     id: window
  6.  
  7.     Column {
  8.          id: column
  9.  
  10.          property int itemCount: window.inPortrait ? 2 : 4
  11.          property int rectangleHeight: Math.round(column.height / itemCount)
  12.  
  13.          anchors.fill: parent
  14.          anchors.margins:  1
  15.          Rectangle {
  16.              id: red
  17.              width: column.width; height: column.rectangleHeight
  18.              color: "red"
  19.              border.color: "white"
  20.              radius: 15
  21.          }
  22.          Rectangle {
  23.              id: green
  24.              width: column.width; height: column.rectangleHeight
  25.              color: "green"
  26.              border.color: "white"
  27.              radius: 15
  28.          }
  29.          Rectangle {
  30.              id: blue
  31.              width: column.width; height: column.rectangleHeight
  32.              color: "blue"
  33.              border.color: "white"
  34.              radius: 15
  35.          }
  36.      }
  37.  
  38.      Row {
  39.  
  40.          spacing: 10
  41.          anchors.bottom: parent.bottom
  42.          Rectangle {
  43.              width: txtAdd.width + 10
  44.              height: txtAdd.height + 10
  45.              Text {
  46.                  id: txtAdd
  47.                  text: qsTr("Add")
  48.                  anchors.centerIn: parent
  49.              }
  50.              MouseArea {
  51.                  anchors.fill: parent
  52.                  onClicked: {
  53.                      green.opacity = 1;
  54.                  }
  55.              }
  56.          }
  57.          Rectangle {
  58.              id: removeBtn
  59.              anchors.bottom: parent.bottom
  60.              width: txtRem.width + 10
  61.              height: txtRem.height + 10
  62.              Text {
  63.                  id: txtRem
  64.                  text: qsTr("Remove")
  65.                  anchors.centerIn: parent
  66.              }
  67.              MouseArea {
  68.                  anchors.fill: parent
  69.                  onClicked: {
  70.                      // Should be like this green.opacity = 0
  71.                      green.opacity = 0.000001;
  72.                  }
  73.              }
  74.          }
  75.      }
  76.  }

—————

I found the solution..just by “wrapping” a rectangle under a parent item would do the trick:
@
Item { width: red.width; height: red.height;

Rectangle { id: red } }

0 replies

 
  ‹‹ How to refresh FolderListModel?      QFileSystemModel isn’t working as expected on meego? ››

You must log in to post a reply. Not a member yet? Register here!