由於初始發帖不足導致編輯。多項短劃線
嗨,
感謝您的幫助!
你說得對,我想最好是包括整個文件,儘管大小:
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