Qt Quick : format date dans un TextInput ou autre
:salut:
Voici un petit bout de code qui peut servir. Il permet de formater automatiquement une zone de saisie du style JJ/MM/AA.
Il y a certainement à l'améliorer, voir y ajouter un calendrier, mais bon, c'est déjà ça ;)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import QtQuick 2.0
import QtQuick.Controls 1.0
import QtQuick.Window 2.0
ApplicationWindow {
property string sauvText
TextField{
id : dateIn
width : 80
Keys.onReleased: {
if (event.key !== Qt.Key_Backspace){
if ((text.length === 2) || (text.length === 5)) {
text = text+'/'
sauvText = text
}
if ((event.key === Qt.Key_Slash) && ((text.length === 4) || (text.length === 7))){
text = sauvText
}
}
}
}
} |