要设置ListView的背景颜色,可以使用ListView的'background'属性。例如:

ListView { background: 'gray' }

要设置ListView中的项的字体颜色,可以使用delegate的属性。例如:

ListView { delegate: Rectangle { width: parent.width height: 40 color: index % 2 === 0 ? 'white' : 'lightgray' Text { text: model.displayText color: 'black' font.pixelSize: 20 anchors.centerIn: parent } } }

这段代码中,我们创建了一个Rectangle作为delegate,并设置了其'color'属性来实现交替的背景颜色效果。然后在Rectangle中添加了一个Text元素,并设置了其'color'属性为黑色。

QML ListView 背景颜色和字体颜色设置

原文地址: https://www.cveoy.top/t/topic/nRvB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录