我正在嘗試創建手風琴qml控件,如this。 首先,我認爲我可以使用組合框並對其進行自定義,但現在我認爲這是不可能的。 有沒有可以使用的標準控件?如果不是,你能幫我控制結構嗎?使用qml創建手風琴控制的正確方法
1
A
回答
3
與QML只是玩
PanelItem.qml
import QtQuick 2.7
import QtQuick.Layouts 1.2
Item {
default property var contentItem: null
property string title: "panel"
id: root
Layout.fillWidth: true
height: 30
Layout.fillHeight: current
property bool current: false
ColumnLayout {
anchors.fill: parent
spacing: 0
Rectangle {
id: bar
Layout.fillWidth: true
height: 30
color: root.current ? "#81BEF7" : "#CEECF5"
Text {
anchors.fill: parent
anchors.margins: 10
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
text: root.title
}
Text {
anchors{
right: parent.right
top: parent.top
bottom: parent.bottom
margins: 10
}
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
text: "^"
rotation: root.current ? "180" : 0
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
root.current = !root.current;
if(root.parent.currentItem !== null)
root.parent.currentItem.current = false;
root.parent.currentItem = root;
}
}
}
Rectangle {
id: container
Layout.fillWidth: true
anchors.top: bar.bottom
implicitHeight: root.height - bar.height
clip: true
Behavior on implicitHeight {
PropertyAnimation { duration: 100 }
}
}
Component.onCompleted: {
if(root.contentItem !== null)
root.contentItem.parent = container;
}
}
}
用法:
import QtQuick 2.7
import QtQuick.Layouts 1.2
import QtQuick.Window 2.0
Window {
visible: true
width: 400
height: 400
ColumnLayout {
anchors.fill: parent
spacing: 1
property var currentItem: null
PanelItem {
title: "Panel 1"
Rectangle {
color: "orange"
anchors.fill: parent
}
}
PanelItem {
title: "Panel 2"
Rectangle {
color: "lightgreen"
anchors.fill: parent
}
}
PanelItem {
title: "Panel 3"
Rectangle {
color: "lightblue"
anchors.fill: parent
}
}
PanelItem {
title: "Panel 4"
Rectangle {
color: "yellow"
anchors.fill: parent
}
}
Item {
Layout.fillWidth: true
Layout.fillHeight: true
}
}
}
相關問題
- 1. 動態創建AJAX手風琴控制
- 2. 手風琴創建手風琴
- 3. 什麼是創建手風琴小部件的語義正確方法?
- 4. Silverlight手風琴控制
- 5. Ajax手風琴控制不起作用
- 6. 如何創建「關閉」Flex手風琴控制?
- 7. 不正確的jquery手風琴菜單
- 8. 創建jQuery手風琴菜單的更好方法?
- 9. 幫助與WPF手風琴控制,VS2010
- 10. Flex手風琴控制:排序標籤?
- 11. 手風琴中的jQuery UI手風琴
- 12. 如何使用telerik控制使用手風琴
- 13. 使用jquery的手風琴
- 14. 用手風琴
- 15. 類似的手風琴問題,但不使用手風琴
- 16. 手風琴內手風琴摺疊父母手風琴
- 17. 重新創建塗鴉手風琴表
- 18. React.js - 創建簡單手風琴例如
- 19. 創建水平手風琴,如附圖
- 20. 手風琴的另一種方法
- 21. 手風琴無法正常工作
- 22. 以編程方式控制angular-ui手風琴的好方法是什麼?
- 23. jQuery的手風琴錯誤::對象不支持屬性或方法「手風琴
- 24. 使用JQuery UI手風琴手風琴菜單
- 25. 的手風琴
- 26. 如何使用jQuery創建多級jQuery的手風琴菜單?
- 27. jq繪製手風琴圖
- 28. 以編程方式控制Dojo手風琴
- 29. 手風琴控制:將用戶控件在窗格
- 30. 的Javascript用於定製手風琴
檢查[這](https://github.com/RealworldSystems/qml-widgets-library /樹/主/ qmltemplates/AccordionList)。 – Tarod
[This](https://github.com/crapp/qaccordion)可能也因爲它的相關性而感興趣。 – armatita
https://stackoverflow.com/questions/43093280/how-to-create-an-animated-variable-size-accordion-component-in-qtquick-qml – dtech