由于初始发帖不足导致编辑。多项短划线
嗨,
感谢您的帮助!
你说得对,我想最好是包括整个文件,尽管大小:
import QtQuick 2.5
import QtQuick.LocalStorage 2.0
import QtQuick.Dialogs 1.2
import QtQuick.Controls 2.1
import QtQuick.Controls.Styles 1.4
import QtQuick.Window 2.0
import QtQuick.Controls.Material 2.1
import "./database.js" as Database
ApplicationWindow {
visible: true
width: 640
height: 480
id: appWindow
x: Screen.width/2 - width/2
y: Screen.height/2 - height/2
title: qsTr("Project Stats")
Material.theme: Material.Dark
ListModel {
id: projectModel
ListElement {
projectID: "123654"
manager: "Schneider"
sponsor: "3466"
}
}
Component {
id: projectDelegate
SwipeDelegate {
id: projectSwipeDelegate
width: parent.width
height: projectDelegateItem.implicitHeight
anchors.horizontalCenter: parent.horizontalCenter
spacing: 10
contentItem: Item {
id: projectDelegateItem
Text {
id: projectID_text
text: "Project ID: " + projectID
font.pointSize: 20
anchors.horizontalCenter: parent.horizontalCenter
font.weight: Font.Black
color: "white"
}
Text {
id: manager_text
text: 'Manager: ' + manager + " Sponsor: " + sponsor
anchors.top: projectID_text.bottom
anchors.horizontalCenter: parent.horizontalCenter
font.weight: Font.Thin
color: "lightgrey"
}
}
onClicked: {
console.log(index, projectModel.get(index).projectID)
if (swipe.complete)
projectModel.remove(index)
else {
//var component= Qt.createComponent("timepointsstackview.qml")
//var loadwin = component.createObject(appWindow)
//loadwin.selected_project = projectModel.get(index).projectID
// stackView.push(Qt.resolvedUrl("timepointsstackview.qml"), {properties: {selected_project: projectModel.get(index).projectID}})
stackView.push(component, {properties: {selected_project: projectModel.get(index).projectID}})
}
}
swipe.right: Label {
id: deleteLabel
text: qsTr("Delete")
color: "white"
verticalAlignment: Label.AlignVCenter
padding: 12
height: parent.height
anchors.right: parent.right
SwipeDelegate.onClicked: projectListView.model.remove(index)
background: Rectangle {
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
}
}
}
}
Item {
Component.onCompleted: {
Database.getDatabase()
Database.getProjects()
}
}
StackView {
id: stackView
anchors.fill: parent
// Implements back key navigation
focus: true
Keys.onReleased: if (event.key === Qt.Key_Back && stackView.depth > 1) {
stackView.pop();
event.accepted = true;
}
initialItem: Item {
width: parent.width
height: parent.height
ListView {
id: projectListView
anchors.fill: parent
clip: true
model: projectModel
delegate: projectDelegate
}
}
}
onClosing: {
if (Qt.platform.os == "android") {
close.accepted = false;
// if (stack.depth > 1) stack.pop();
}
}
}
同时我已经删除了该行/列的东西,我把在得到它以某种方式工作,虽然我没有它开始。
我也在实际发布前试验过隐式高度,但可惜无济于事。以上是我当前的代码,但在现场投入
height: projectDelegateItem.implicitHeight
(probabaly不正确的或错误的参考?只好把它从你的建议改变,因为我已经拿出了行)导致渲染只有一个点。
感谢您的时间,到目前为止,也如果你仍然有耐心给我一个线索在哪里拐弯螺丝...
你好,欢迎来到StackOverflow。我不相信你,这是“你得到的代码”。你可能还有更多,就像我们需要测试你的代码所需要的'ListView'和'ListModel'。对于未来的问题,请不要忘记这些。阅读[this](http://stackoverflow.com/help/mcve)关于如何呈现一个好例子,我们可能会合作。如果他们能够专注于自己的问题,而其他人则更有帮助,并且不要费尽心思先复制问题。尽管如此,我希望我的回答能帮助你解决和解决你的问题。如果是这样,我会很感激,如果你将它标记为*接受* ;-) – derM
现在你需要给你的文本(例如'text1'和'text2')提供'id's。然后你可以计算高度为height:text1.implicitHeight + text2.implicitHeight。问候:-) – derM