Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

Calendar in Qt via QML

$
0
0
        Item {             id: dateGrid             width: parent.width             anchors.top: dayLabels.bottom             anchors.topMargin: 5             anchors.bottom: parent.bottom             property int currentActive: -1             Grid {                 columns: 7                 rows: dateLabels.rows                 spacing: 10                   Repeater {                     id: repeater                     model: firstDay + daysInMonth                     Rectangle {                         property bool highLighted: false                         property color normalColor                           Component.onCompleted: {                             if (index < firstDay)                                 normalColor = calendar.color="green";                               else                             {                                 if(isToday(index-firstDay))                                     normalColor = "yellow";                                 else                                     normalColor ="#eeeeee"                             }                         }                         color: dateMouse.pressed?"blue":(highLighted?"grey":normalColor)                         width: (calendar.width - 20 - 60)/7                         height: (dateGrid.height - (dateLabels.rows - 1)*10)/dateLabels.rows                           Text {                             id: dateText                             color: highLighted?"yellow":"black"                             anchors.centerIn: parent                             text: index + 1 - firstDay                             opacity: (index < firstDay) ? 0 : 1                             font.bold: isToday(index - firstDay)  || highLighted                         }                           MouseArea {                             id: dateMouse                             enabled: index >= firstDay                             anchors.fill: parent                             onClicked: {                                 var clickedDate = new Date( showDate.getFullYear(), showDate.getMonth() + 1, index + 1 - firstDay)                                 console.log(Qt.formatDate(clickedDate, "dd/MM/yyyy"))                                 if (dateGrid.currentActive != -1) {                                     // unselect it                                     repeater.itemAt(dateGrid.currentActive).highLighted = false;                                 }                                   if (!isToday(index - firstDay)){                                     highLighted = true                                     dateGrid.currentActive = index                                 }                             }                         }                     }                 }             }         }     } }

Viewing all articles
Browse latest Browse all 4972

Trending Articles