Перекрытие элементов управления QML - PullRequest
0 голосов
/ 14 мая 2019

Что я тут не так делаю. Мои элементы перекрывают друг друга в моем списке, используя мой пользовательский делегат. Вот что я получаю ...

qt,

Вот что я пытаюсь сделать ...

enter image description here

QML

import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3

Frame {
    ListView {
        implicitWidth: 250
        implicitHeight: 250
        clip: true

        model: ListModel {
            ListElement {
                done: true
                description: "Wash the car this could be a really long message with some multiline support\n we will see how it works."
            }
            ListElement {
                done: false
                description: "Fix the car"
            }
            ListElement {
                done: false
                description: "Sell the car"
            }
            ListElement {
                done: true
                description: "Wash the car"
            }
            ListElement {
                done: false
                description: "Fix the car"
            }
            ListElement {
                done: false
                description: "Sell the car"
            }
            ListElement {
                done: true
                description: "Wash the car"
            }
            ListElement {
                done: false
                description: "Fix the car"
            }
            ListElement {
                done: false
                description: "Sell the car"
            }
        }

        delegate: Row {
            spacing: 6
            width: parent.width

            Rectangle {
                id: newsicon
                width: 16
                height: 16
                color: "steelblue"
            }

            Column {
                Rectangle {
                    color: "lightgrey"

                    Label {
                        id: messageText
                        text: model.description
                        width: parent.width
                        wrapMode: Label.Wrap
                    }
                    Label {
                        id: dateText
                        text: "Dec 20, 2019"
                        wrapMode: Label.Wrap
                    }
                }
            }
        }

        ScrollBar.vertical: ScrollBar {
            active: true
        }
    }
}

1 Ответ

2 голосов
/ 14 мая 2019

На самом деле, ваша проблема в том, что вы поместили свои метки в невидимый прямоугольник нулевого размера (поскольку он имеет height==0 и width==0), оба в положении (0, 0).Вместо Label s в Column вы добавляете Rectangle.Вот почему у вас есть это перекрытие.


Лично я бы порекомендовал вам использовать Layouts, например:

Frame {
    anchors.centerIn: parent
    ListView {
        implicitWidth: 250
        implicitHeight: 250
        clip: true

        model: listModel
        delegate: RowLayout {

            Rectangle {
                id: newsicon
                width: 16
                height: 16
                color: "steelblue"
            }

            ColumnLayout {
                Layout.fillWidth: true
                spacing: 0
                Label {
                    id: messageText
                    text: model.description
                    width: parent.width
                    wrapMode: Label.WrapAtWordBoundaryOrAnywhere
                }
                Label {
                    id: dateText
                    text: "Dec 20, 2019"
                    font.italic: true
                    color: "grey"
                    wrapMode: Label.WrapAtWordBoundaryOrAnywhere
                }
            }

        }
        ScrollBar.vertical: ScrollBar { active: true }
    }
}

И у вас будет:

Layouts example

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...