[SOLVED] Height of ListView delegate(multidelegate)



  • How can I set the height of multiDelegate? The height of multiDelegate depends on type of delegate (imgDelegate or txtDelegate)

    Below my delegate code (MultiDelegate.qml)

    @
    import QtQuick 1.1

    Item {
    id: multiDelegate
    width: multiDelegate.ListView.view.width

    Component {
    id: imgDelegate

    Image {
      id: img
      source: value
      fillMode: Image.PreserveAspectFit
      asynchronous: true
    }
    

    }

    Component {
    id: txtDelegate

    Text {
      id: txt
      text: value
      verticalAlignment: Text.AlignVCenter
      horizontalAlignment: Text.AlignHCenter
      wrapMode: Text.Wrap
    }
    

    }

    Loader {
    id: itemDisplay
    anchors.fill: parent;
    anchors.topMargin: 2
    anchors.bottomMargin: 2
    sourceComponent: type ? imgDelegate : txtDelegate
    }

    }@



  • Hello,

    Try following:

    1. Set @ multiDelegate.height: itemDisplay.height @

    According to documentation:
    bq. If an explicit size is not specified for the Loader, the Loader is automatically resized to the size of the loaded item once the component is loaded.



  • I tried following

    @
    import QtQuick 1.1

    Item {
    id: multiDelegate
    width: multiDelegate.ListView.view.width
    height: itemDisplay.height
    @

    but it didn't work. I got following error

    @
    MainPage.qml QML Item: Binding loop detected for property "height"
    MultiDelegate.qml QML Loader: Possible anchor loop detected on fill.
    MultiDelegate.qml QML Loader: Possible anchor loop detected on fill.
    MainPage.qml QML Item: Binding loop detected for property "height"
    MainPage.qml QML Item: Binding loop detected for property "height"
    MultiDelegate.qml QML Loader: Possible anchor loop detected on fill.
    @



  • Problem solved

    I modified Loader element like this

    @
    Loader {
    id: itemDisplay
    sourceComponent: type ? imgDelegate : txtDelegate
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.