Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any DatePicker control for Qt 5?

I'm writing my first QML/Javascript app for QtQuick 2.0. I need to place a DatePicker control, but I haven't found any control like that under QtQuick.Controls -and nowhere, in fact-.

I'm starting to believe there is no way to call a 'native' DatePicker in QML. Do I have to implement one or there is exist one?

like image 330
cmolina Avatar asked Jan 16 '14 04:01

cmolina


3 Answers

Just in case anyone else stumbles upon this, there is a Calendar element in QtQuick.Controls by now. This should make the implementation of such a Datepicker a lot easier: http://qt-project.org/doc/qt-5/qml-qtquick-controls-calendar.html

like image 146
anderas Avatar answered Nov 10 '22 10:11

anderas


Well, I had to make my own control. It is called Datepicker.

Datepicker example

It is intented to used in this way:

import QtQuick.Controls 1.1

ApplicationWindow {
    id: main

    Datepicker {
        id: myDate
        activeWindow: main
        width: 200
    }
}

It asumes you are using it from a Window object, and needs the parent reference to show the datepicker in the correct position (it shows a calendar in a new window).

You can download the source code from: https://bitbucket.org/camolin3/datepicker

This is the first version and need a lot of polish to be ready, but is a start point.

like image 35
cmolina Avatar answered Nov 10 '22 09:11

cmolina


**Code for DatePicker. Try this one **

*TextField {
    id: textDate
    x: 10
    y: 42
    width: 175
    height: 33
    placeholderText: qsTr("Text Field")
    text:Qt.formatDate(cal.selectedDate, "dd-MM-yyyy")
    font.bold: true
    font.family:"times new roman"
    font.pointSize: 12
}
Button {
    id: button
    x: 198
    y: 42
    width: 25
    height: 29
    Image {
        x: -4
        y: -4
        id: img
        width: 36
            height: 44
            source: "/Images/calendar-512.png"
    }
    onClicked:{
        cal.visible=true
    }
}
Calendar{
           id:cal
           x: 10
           y: 82
           width: 220
           height: 205
           visible: false
           selectedDate: new Date()
           onClicked:  {
               textDate.text=Qt.formatDate(cal.selectedDate, "dd-MM-yyyy");
                cal.visible=false
           }
}*
like image 3
Lenil K V Avatar answered Nov 10 '22 10:11

Lenil K V