程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高?

开发过程中遇到Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高的问题如何解决?下面主要结合日常开发的经验,给出你关于Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高的解决方法建议,希望对你解决Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高有所启发或帮助;

我正在尝试调整 TreeVIEw 的行高以自动适应其 itemDelegate 中的内容,但我不知道该怎么做。

到目前为止,我尝试在我的 itemDelegate 对象中创建一个属性“lines”,但是每次我尝试访问它时,QML 都说我的 treeDeleg 项未定义。

有没有办法得到我想要的结果?

编辑:按照 JaRMAN 所说的,不可能通过 ID 引用 delegateComponent。那么,有没有一种方法可以自动使行高适应其内容?类似于 CSS 中的“height: auto”。这非常重要,因为长值会使我的界面难以阅读。

如果所有其他方法都失败了,是否有更好的组件来创建能够包含长的、可编辑的值的树形视图?

@H_613_13@ma​​in.qml :

TreeVIEw 
{

    ID:treeVIEw
    anchors.top:  rowInfo.bottom
    anchors.left: parent.left
    anchors.right: parent.right
    anchors.bottom: parent.bottom
    itemDelegate: TreeDelegate
    {
        ID: treeDeleg
    }
    style: TreeVIEwStyle
    {
        ID: styleTree
        
        rowDelegate:rectangle
        {
            ID : rowDeleg
            height: styleData.SELEcted ? 75 : 25 * treeDeleg.lines
            color:
            {
                var basecolor = styleData.alternate ? "white" : "#d9edf7" 
                return styleData.SELEcted ? "yellow" : basecolor
            }
        }


    }


    Component.onCompleted:
    {
         treeVIEw.model = Qt.binding(function()
         {
             if (typeof theModel !== "undefined")
             {
                 return theModel;

             }
             else
             {
                return null;
             }
         });
    }
    tableVIEwcolumn
    {
        ID:column1
        role: "name"
        title: "name"
        wIDth: 450
    }
    tableVIEwcolumn
    {
        ID:column3
        role: "Value"
        title: "Value"
        wIDth: 400
    }
    tableVIEwcolumn
    {
        ID:column4
        role: "Desc"
        title: "Description"
        wIDth: 750
    }
}

TreeDelegate.qml

Item
{
    ID: item
    wIDth : parent.wIDth
    height : 25
    property var lines: null

    

    TextEdit
    {
        ID: text1
        Font.pixelSize: 14
        Readonly: true
        focus: false
        wIDth : parent.wIDth
        height: 25 * lineCount
        anchors.left: parent.left
        wrapMode: TextEdit.Wrap
        text: (styleData.value !== null) ? (styleData.value.text + styleData.value.ID) : "";
        verticalAlignment: Text.AlignVCenter
        horizontalAlignment: Text.Alignleft

        Component.onCompleted:
        {
            lines = text1.lineCount == 0 ? 1 : text1.lineCount;
            console.log("lines : " + lines);
        }

    }
}
```

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高全部内容,希望文章能够帮你解决Qt 5.11.3 - QML - treeView - 根据 itemDelegate 属性调整行高所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:-根据