1
A
回答
2
,可以使用樣式可以輕鬆完成。我建議您查看$QTHOME/qml/QtQuick/Controls[/Styles/Base]
中的QML控件/樣式源,以瞭解QML控件的默認樣式。
import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.4
Window {
id: rootWindow
visible: true
height: 800
width: 800
Rectangle {
width: 350
height: 100
color: "#555"
anchors.centerIn: parent
Slider {
anchors.centerIn: parent
minimumValue: 1
maximumValue: 5
stepSize: 1
tickmarksEnabled: true
width: 300
style: SliderStyle {
handle: Rectangle {
width: 18
height: 30
border.width: 2
border.color: "#555"
color: "#CCC"
radius: 5
}
groove: Rectangle {
height: 15
width: parent.width
anchors.verticalCenter: parent.verticalCenter
color: "#CCC"
}
tickmarks: Repeater {
id: repeater
model: control.stepSize > 0 ? 1 + (control.maximumValue - control.minimumValue)/control.stepSize : 0
Item {
Text {
y: repeater.height + 5
width : repeater.width/repeater.count
x: width * index
height: 30
color: "#CCC"
font.pixelSize: 20
text: getText()
horizontalAlignment: getAlign()
function getText() {
if(index === 0) return "THIN"
else if(index === repeater.count - 1) return "THICK"
else return "";
}
function getAlign() {
if(index === "0") return Text.AlignLeft
else if(index === repeater.count - 1) return Text.AlignRight
else return Text.AlignHCenter;
}
}
Rectangle {
color: "#CCC"
width: 2 ; height: 5
y: repeater.height
x: styleData.handleWidth/2 + index * ((repeater.width - styleData.handleWidth)/(repeater.count-1))
}
}
}
}
}
}
}
這個例子充滿了過多和毫無價值的代碼,但這對理解很有幫助。
0
它似乎並不像他們可以刻度線的一部分,但是你可以很容易地與單獨的文本標籤,實現這一點:
Slider {
id: slide
width: 200
}
Text {
text: "THIN"
anchors.top: slide.bottom
anchors.left: slide.left
}
Text {
text: "THICK"
anchors.top: slide.bottom
anchors.right: slide.right
}
相關問題
- 1. d3.js - 開始和結束刻度
- 2. XSLT離開開始和結束標記
- 3. 變化AngularJS開始和結束標記
- 4. XML開始和結束標記
- 5. 開始和結束標記之間的文本的術語?
- 6. 無法獲取開始和結束標記之間的文本
- 7. REGEX - 替換結束標記和開始標記之間的文本
- 8. 記事本++匹配pl sql開始和結束塊
- 9. BNF語法匹配開始標記和結束標記
- 10. jQuery的搜索開始標記和結束標記字符串
- 11. 開始標記和結束標記之間的線條
- 12. wxPython:將文本標籤分配到滑塊上的刻度
- 13. Javafx滑塊:文本作爲刻度標籤
- 14. 範圍滑塊開始和結束的圈子
- 15. 獲取kendo滑塊的開始值和結束值
- 16. 如何獲得傳單滑塊的開始和結束
- 17. jquery ui滑塊 - 反向開始和結束位置
- 18. SQL - 打破了開始/結束時刻15分鐘記錄
- 19. 如何添加刻度標記沿jQuery Mobile的滑塊
- 20. 僅在軸的開始和結束時刻纔會出現
- 21. 設置Asp.Net表刻度線開始,在軸最小值和結束,最大值
- 22. 在RubyMine中同時編輯HTML開始和結束標記
- 23. 在開始和結束點(!)
- 24. Tkinter文本標記範圍從開始和結束索引值從wordstart到wordend?
- 25. 文本是不允許的開始和結束標記更新面板之間
- 26. 開始和結束標記不匹配:元行4和頭
- 27. Excel從開始和結束編號和標記創建列表
- 28. 目標C:開始點和結束點
- 29. MJPEG的開始和結束標籤?
- 30. 記事本++如何選擇多個始終以相同單詞開始和結束的文本塊?
我還沒有測試過這段代碼,它肯定沒有看起來毫無價值,正是我在找的東西。 tickmarksEnabled:true在這裏扮演一個主要角色,在qt文檔中沒有提到任何地方。 ne方式謝謝。 –