yeguoxiong的个人主页

http://www.qtcn.org/bbs/u/41539  [收藏] [复制]

yeguoxiong

  • 59

    关注

  • 179

    粉丝

  • 432

    访客

  • 等级:侠客
  • 总积分:147
  • 男,1985-07-02
  • 四川

最后登录:2024-04-15

更多资料

日志

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

分类:默认分类|回复:0|浏览:536|全站可见|转载
 

下一篇:

上一篇: Qt程序打包发布方法

Powered by phpwind v8.7 Certificate Copyright Time now is:04-19 23:24
©2005-2016 QTCN开发网 版权所有 Gzip disabled