Browse Source

Add DropDown

master
pouya 1 year ago
parent
commit
8078b2e9d6
  1. 18
      Page1.qml
  2. 75
      SepantaUiKit/SKDropDown/SKDropDown.qml

18
Page1.qml

@ -45,11 +45,19 @@ Item {
spacing: 20 spacing: 20
SKMultiOption {} SKMultiOption {}
SKDropDown { SKDropDown {}
}
} }
} }
ListView {
y: 300
x: 300
width: 400
height: 400
model: ["A", "b", "c"]
delegate: Text {
text: "Hi"
color: "white"
}
}
} }

75
SepantaUiKit/SKDropDown/SKDropDown.qml

@ -14,7 +14,7 @@ Item {
property var listOfObj: [] property var listOfObj: []
property var options: ["High", "Low", "Medium"] property var options: ["High", "Low", "Medium"]
property var currentText: options[currentIndex] property var currentText: options[currentIndex]
property int currentIndex: 0 property int currentIndex: idContentItem.currentIndex
property var stateOfComponent: Setting.Enable property var stateOfComponent: Setting.Enable
@ -50,8 +50,10 @@ Item {
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onPressed: { onPressed: {
if (idPopup.visible)
idPopup.open() idPopup.close()
else
idPopup.open()
} }
} }
} }
@ -59,14 +61,42 @@ Item {
Popup { Popup {
id: idPopup id: idPopup
width: parent.width width: parent.width
height: 500 y: idBackGround.height
y: 0 implicitHeight: contentItem.implicitHeight
padding: 0
visible: true
onVisibleChanged: console.log("Visible: " + visible)
closePolicy: Popup.CloseOnPressOutsideParent
contentItem: ListView { contentItem: ListView {
implicitHeight: idBackGround.height id: idContentItem
implicitHeight: contentHeight
width: parent.width
model: options model: options
currentIndex: 0
delegate: Item {
id: idDelegate
width: parent.width
height: idBackGround.height
Text {
leftPadding: 10
anchors.fill: parent
text: modelData
font: Fonts.h5
color: Colors.tertiaryEnable
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignVCenter
}
MouseArea {
anchors.fill: parent
onClicked: {
currentIndex = index
idPopup.close()
}
}
}
} }
background: Rectangle { background: Rectangle {
anchors.fill: parent
radius: Setting.mediumRadius radius: Setting.mediumRadius
color: "transparent" color: "transparent"
border.color: Colors.tertiaryEnable border.color: Colors.tertiaryEnable
@ -74,35 +104,4 @@ Item {
clip: true clip: true
} }
} }
// ComboBox {
// id: control
// anchors.fill: parent
// model: options
// font: Fonts.h5
// popup: Popup {
// y: control.height - 1
// width: control.width
// implicitHeight: contentItem.implicitHeight
// padding: 1
// contentItem: ListView {
// clip: true
// implicitHeight: contentHeight
// model: control.popup.visible ? control.delegateModel : null
// currentIndex: control.highlightedIndex
// }
// background: Rectangle {
// anchors.fill: parent
// radius: Setting.mediumRadius
// color: "transparent"
// border.color: Colors.tertiaryEnable
// border.width: 1
// clip: true
// }
// }
// }
} }

Loading…
Cancel
Save