QML内怎么根据字符串长度设置对应width的值

对于界面上文字字符串显示,qml 中有Text控件。而Text控件中有个

contentWidth属性。可以获取字符串宽度。当然和字体字体大小有关。

               width:{level1Width =Math.max(level1Width,txt1.contentWidth+20);return  level1Width;}//100
                height: parent.height
                color: level1MenuHoverIndex === index ? '#b8e1fc' : '#fff'
                Text {
                    id: txt1
                    text: modelData.Name
                    anchors.verticalCenter: parent.verticalCenter
                    font.family: '黑体'
                    font.bold:  level1MenuHoverIndex === index
                    x: 5
                }


打赏:

posted @ 2018-11-01 08:23  blueridge  阅读(3226)  评论(0编辑  收藏  举报