c++ - 我如何在 QML 中设置样式表?(只有 QML 没有 C++)

标签 c++ qt qml

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

enter image description here

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

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
  } 
}

在我的例子中,我想用我的滚动条图像来创建。

我试了「source: "./bar.bng" 」,但是说ScrollBar没有参数"source"。我如何使用自定义图像。

最佳答案

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

Here是如何实现它们的示例。

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

关于c++ - 我如何在 QML 中设置样式表?(只有 QML 没有 C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49273738/

相关文章:

c++ - 保护 QML 源代码免遭抄袭

c++ - 运算符重载中的 const 返回类型

c++ - 为什么对共享库本身中定义的符号使用全局偏移表?

c++ - 无法使用 Eigen 库编译 ChibiOS

file - 如何在Qt中将文本文件打印到打印机?

qt - QtWebEngine 依赖应用程序的静态构建

c++ - Qt : Display a picture during application loading

c++ - 如何将私有(private)类的值返回到主类

c++ - 启动 Qt5 控制台应用程序 : invokemethod vs singleshot timer

qt - QML取消选中ExclusiveGroup中的选中按钮