我正在尝试弄清楚如何执行多行 ListElement 属性。
我有一个带有 ListElements 的 ListModel,如下所示:
ListElement {
key: "key";
value: 1;
description: "Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely."
}
我可以通过简单地输入换行符来换行,但随后的行不会与文本块对齐。
description: "Very long, full paragraph description that extends way off the screen which I would like to wrap in code nicely."
当我尝试在文本上按 Tab 键将其对齐时,当描述打印到屏幕上时,它会导致大量空白(这是有道理的,但显然不是我想要的)。
description: "Very long, full paragraph description
that extends way off the screen which I would like to
wrap nicely in code."
Very long, full paragraph description that extends way off the screen which I would like to
wrap in code nicely.
我尝试通过“+”连接,但这会产生错误:ListElement:无法使用脚本获取属性值。
我尝试过像在 .pro 文件中那样使用反斜杠,但这也不起作用。
换行符可以工作,但它们并不重要,因为它们不能解决空格问题。
Very long, full paragraph description
that extends way off the screen which I would like to
wrap in code nicely.
如果有人有任何想法,我将不胜感激。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
对于您使用的直接创建 ListElements 的实现,我没有直接的解决方案。但是 ListModel 的 .append() 方法确实将 JS 对象作为参数。这些支持多行字符串。因此,您可以像这样在组件完成时附加它们,而不是像这样创建 ListElements:
ListModel { id:listModel Component.onCompleted: { listModel.append({ "key": "key", "value": 1, "description": "Very long, full paragraph description" + "that extends way off the screen which" + "I would like to wrap in code nicely." }) } }