Qt QML日历类型,强制可见年份无效
这是我的代码:Qt QML日历类型,强制可见年份无效,qt,qml,Qt,Qml,这是我的代码: Rectangle { id: calendarPopUp visible: false; border.width: 0 color: "#ffffff" anchors.left: parent.left anchors.top: parent.top width: parent.width z: 10; VMComboBox{ id: yearPicker width:
Rectangle {
id: calendarPopUp
visible: false;
border.width: 0
color: "#ffffff"
anchors.left: parent.left
anchors.top: parent.top
width: parent.width
z: 10;
VMComboBox{
id: yearPicker
width: parent.width
//vmModel: ["1999", "2000"]
vmModel: {
var ans = [];
var cyear = 2018;
var fyear = cyear - 120;
for (var i = cyear; i >= fyear; i--){
ans.push(i)
}
calendar.minimumDate = new Date(fyear, 0, 1);
calendar.maximumDate = new Date(cyear, 0, 1);
return ans;
}
font.family: viewHome.robotoR.name
anchors.top: parent.top
anchors.topMargin: 2
anchors.horizontalCenter: parent.horizontalCenter
onCurrentIndexChanged: {
var year = yearPicker.currentText;
console.log("Changing visible year to: " + year);
calendar.visibleYear = parseInt(year);
}
}
Calendar {
id: calendar
width: parent.width
anchors.top: yearPicker.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
}
VMComboBox是一个自定义组合框。我需要这个来选择出生日期。然而,QML日历并没有提供一种可以快速返回时间的方式。我认为添加一个组合框来选择年份将是最快的方法
但是,在“我的日历”元素上设置visibleYear不会更改可见年份。它有时会改变年份,但几乎是随机的。我看不到所选年份和显示年份之间的差异有任何关系
有什么想法吗?好的,我已经测试了
日历
项,我无法重现您提到的问题。
这是一个测试代码,我想它会对你有用
导入QtQuick 2.11
导入QtQuick.Controls 2.4
导入QtQuick.Layouts 1.4
将QtQuick.Controls 1.4导入为Controls1
应用程序窗口{
标题:qsTr(“日历”)
宽度:300
身高:400
可见:正确
列布局{
锚定。填充:父级
组合框{
Layout.fillWidth:true
布局。首选高度:40
属性int year:new Date().getFullYear()
型号:{
var-arr=[];
对于(var i=年份;i>(年份-50);i-)
arr.push(i);
返回arr;
}
currentIndex:year-calendar.visibleYear
一旦货币兑换:{
calendar.visibleYear=年份-当前索引;
}
}
组合框{
Layout.fillWidth:true
布局。首选高度:40
型号:[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月”]
当前索引:calendar.visibleMonth
一旦货币兑换:{
calendar.visibleMonth=当前索引;
}
}
控件1.日历{
id:日历
Layout.fillWidth:true
Layout.fillHeight:true
navigationBarVisible:false
}
}
}
工作起来很有魅力。您的代码无法运行。请预选代码并提供。你应该澄清这个问题。到底是什么问题?这一年的变化有时意味着什么?对不起,我很忙,无法创建一个完整的示例。我曾希望有人能用QML日历输入出生日期。它有时会改变年份,也就是说。我更改了年份,但未记录可见年份的任何更改。我再次改变它,可见的一年改变为某一年,而不是我选择的一年。我再次改变它,它可能会改变,也可能不会。