日志
QML下拉Calendar
2021-06-09 08:43
import QtQuick 2.6import QtQuick.Controls 1.4
import QtQuick.Controls 2.15 ComboBox { id: calendarBox implicitWidth: 260 implicitHeight: 30 property string currentDate: Qt.formatDateTime(new Date(), "yyyy-MM-dd") FontLoader { id: localFont; source: "file:fonts/msyhbd.ttf" } font{ family: localFont.name; pointSize: 9 } model:[currentDate] background: Rectangle { color: "#fcfcfc" border.color: "#b1b1b1" radius: 2 } popup: Popup { id: calendarPopup width: calendarBox.width height: 290 y: calendarBox.height-1 padding: 0 Calendar { width: calendarBox.width height: parent.height selectedDate: calendarBox.currentText onClicked: if(true) { calendarPopup.close() currentDate = Qt.formatDateTime(selectedDate, "yyyy-MM-dd") } } } indicator: Rectangle{ height: parent.height width: 30 anchors.right: parent.right color: "transparent" Canvas { width: 8 height: 4 anchors.centerIn: parent onPaint: { var ctx = getContext("2d") ctx.lineWidth = 0 ctx.strokeStyle = "#a1a1a1" ctx.fillStyle = "#a1a1a1" ctx.beginPath() ctx.moveTo(0, 0) ctx.lineTo(width/2, height) ctx.lineTo(width, 0) ctx.closePath() ctx.fill() ctx.stroke() } } } delegate: ItemDelegate { width: calendarBox.width highlighted: calendarBox.highlightedIndex === index contentItem: Text { verticalAlignment: Text.AlignVCenter font{ family: localFont.name; pointSize: 9 } elide: Text.ElideRight text: name color: "#464646" } } } |
下一篇: 无
上一篇: Qt程序打包发布方法