1

I have a 2-dimension qvariantlist which I would like to display in QML. I have been trying with a Listview but it only display the dimensions that you indicate. Ex array[0] array1 ...

The following code displays only the first dimension...:

        Rectangle {
        id: rectangle
        height: 300
        anchors.top: userFields.bottom
        width: parent.width
        ListView {
                id: listView
                anchors.centerIn: parent
                width: 180
                height: 200

                model: RdaDevicePropertyAcess.rdaDataAcquired[userFields.devicePropertyText + '#' + userFields.fieldText]

                delegate: Row {
                    Rectangle {
                        id: first
                        width: listView.width / 3
                        height: 30

                        Text {
                            anchors.centerIn: parent
                            text: modelData[0]
                            font.pointSize: 20
                        }
                    }

                }
            }
    }

I was taking a look of this POST but i didn't work for me. I would like to have the same but displaying it into a qml object.

I also have been trying to use the createObject()javascript function but it didn't work for me neither.

Does anyone has any suggestion?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
arodrprope
  • 51
  • 9
  • you should create a two-dimensional ListView if you have a two-dimensional list, i.e. a ListView on the place where you now have a Text – Amfasis Aug 07 '18 at 10:47
  • 1
    show your QVariantList and provide a [mcve] – eyllanesc Aug 07 '18 at 11:01
  • It looks like you need `TableView`, not `ListView`. what is 2-dimension qvariantlist in your case? Provide an example. – folibis Aug 07 '18 at 11:23

2 Answers2

1

I reply to myself. Finally I solved the problem with the following QML code. I think it will help many people to save time.

        Grid {
        id: rectangle
        height: 1000
        columns: _model.myQvariantList.length
        anchors.top: userFields.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        width: 1000
        Repeater {
            model: _model.myQvariantList[0].length
            Repeater {
                model: _model.myQvariantList.length
                id: repeater1
                property int outerIndex: index
                Rectangle {
                    width: 20; height: 20
                    Text
                    {
                        anchors.centerIn: parent
                        text: _model.myQvariantList[index][repeater1.outerIndex]
                        font.pointSize: 10
                    }
                }
            }
        }
    }
arodrprope
  • 51
  • 9
0

I fill the 2-dimensional qvariantlist:

      case DataType::DT_FLOAT_ARRAY_2D:{
      const  float * array= entry->getArrayFloat2D(rowCount, columnCount);
      QVariantList list;
      for (unsigned long row=0; row < rowCount;row++) {
             QVariantList rows;
             for (unsigned long col=0; col < columnCount;col++) {
                rows.append(array[(row*columnCount+col)]);
             }
             list.append(QVariant::fromValue(rows));
          }
      return list;
   }

Then in the QML part I try to display the 2D qvariantlist:

   delegate: Row {
                                spacing: 5;
                                Repeater {
                                    model: qvariantListObject
                                    Rectangle {
                                        width: listView.width / 3
                                        height: 30

                                        Text {
                                            anchors.centerIn: parent
                                            text: modelData[index]
                                            font.pointSize: 12
                                        }
                                    }
                                }
                           }

But it is only repeating the same row several times.

arodrprope
  • 51
  • 9