代码之家  ›  专栏  ›  技术社区  ›  Ryou

如何在QML中设置样式表?(仅QML无C++)

  •  0
  • Ryou  · 技术社区  · 8 年前

    我想创建一个自定义滚动条。像这样。

    enter image description here

    这是我的代码,我想在Qml中使用滚动条组件。

    Rectangle {
    id: frame
    clip: true
    width: 160
    height: 160
    border.color: "black"
    anchors.centerIn: parent
    
    Text {
        id: content
        text: "ABC"
        font.pixelSize: 160
        x: -hbar.position * width
        y: -vbar.position * height
    }
    
    ScrollBar {
        id: vbar
        hoverEnabled: true
        active: hovered || pressed
        orientation: Qt.Vertical
        size: frame.height / content.height
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.bottom: parent.bottom
      } 
    }
    

    在我的情况下,我想用 我的滚动条图像 。

    我试过了 来源:“/巴bng” ,但它说滚动条没有参数“source”。如何使用自定义图像。

    1 回复  |  直到 6 年前
        1
  •  1
  •   rsht    8 年前

    样式表(以.qss文件的形式,用于QWidget)是 不用于QML 。

    Here 这些示例说明了如何实现它们。

    有关您的确切用例,请查看 Customizing ScrollBar