Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. verticalCenter in ListView (Delegate) not working

verticalCenter in ListView (Delegate) not working

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 428 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.
  • Q Offline
    Q Offline
    QTmox
    wrote on last edited by QTmox
    #1

    Hey guys! I'm currently working on an exercise that revolves around ListViews, delegates and so on.

    This is what my application currently looks like:

    http://www.directupload.net/file/d/4141/obiumyrm_jpg.htm

    All I want is to center the second column of text just like the first column. However, I only manage to get it to the top or the bottom of the row - never in the center.

    Can any of you point out my mistake why I managed to but the first column of text nicely into the row's center but can't get it to work on the second one? Thanks in advance! :)

    This is my source code:

    main.qml

    import QtQuick 2.3
    import QtQuick.Controls 1.2
    
    ApplicationWindow {
        id: root
    
    width: 800; height: 600   
    
    function readFile() {
        var request = new XMLHttpRequest()
    
        request.open('GET', 'qrc:/Kommilitonen.txt')
        request.onreadystatechange = function(event) {
    
    
            if(request.readyState == XMLHttpRequest.DONE)
            {
                console.log(request.responseText)
                view.model = JSON.parse(request.responseText)
            }
        }
    
        request.send();
    }
    
    ListView {
        id: view
    
        property real delegateOpacity: 0.5
    
        anchors {fill: parent; margins: 2}
    
        delegate: KommiDelegate {}
    
        spacing: 4
        cacheBuffer: 50
    }
    
    Component.onCompleted: {
        root.visible = true
        readFile();
    }
    

    }

    KommiDelegate.qml

    import QtQuick 2.3
    
    Rectangle {
    id: delegate01
    anchors{left: parent.left; right: parent.right}
    height: 100
    border.width: 2
    border.color: "lightsteelblue"
    radius: 10
    clip: true
    opacity: 0.5
    scale: 0.9
    
    NumberAnimation{
        id: animateOpacity
        target: delegate01
        properties: "opacity"
        from: 0.9
        to: 1.0
        easing {type: Easing.OutBack; overshoot: 500}
    }
    
    
    
    MouseArea {
        anchors.fill: parent
        onPressed: {
            if(parent.opacity == 0.5)
                parent.opacity = 1.0
            else
                parent.opacity = 0.5
            if(parent.scale==0.9)
                parent.scale = 1.0
            else
                parent.scale = 0.9
    
        }
    }
    
        Image {
            id: img
            anchors.left: parent.left
            anchors.leftMargin: 20
            source: modelData.image
            smooth: true
            opacity: 0.3
            Behavior on opacity {NumberAnimation{easing.type:Easing.OutQuad}}
    
        }
    
        Column {
            id: column
            height: 50
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: img.right
            anchors.leftMargin: 20
            Text{text: 'First Name: ' + modelData.forename}
            Text{text: 'Name: ' + modelData.name}
            Text{text: 'University Course: ' + modelData.course}
            Text{text: 'Age: ' + modelData.age}
    
    
        }
    
    
    
    
    
    ListView
    {
        anchors.left: column.right
        anchors.leftMargin: 20
        anchors.verticalCenter: parent.verticalCenter
    
        id: viewClass
    
        delegate: ClassDelegate {}
    
        spacing: 4
        cacheBuffer: 50
    
        model: modelData.modules
    }
    

    }

    ClassDelegate.qml

    import QtQuick 2.0
    
    
    Rectangle {
        id: classDelegate
        anchors{left: parent.left; right: parent.right}
        visible: true
    
            Column {
    
                id: column2
                Text{text: 'Description: ' + modelData.name}
                Text{text: 'ID: ' + modelData.identificationCode}
                Text{text: 'Severity: ' + modelData.severity}
                Text{text: 'Group: ' + modelData.lernenGroup}
            }
    

    }

    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