Qt Qml日历-选择开始日期和结束日期
我想知道是否可以在这张图片中编写类似的代码,因为我更喜欢只显示一个日历来选择开始日期和结束日期,而不是显示两个日历 试试这个Qt Qml日历-选择开始日期和结束日期,qt,qml,Qt,Qml,我想知道是否可以在这张图片中编写类似的代码,因为我更喜欢只显示一个日历来选择开始日期和结束日期,而不是显示两个日历 试试这个 import QtQuick 2.12 import QtQuick.Window 2.12 import QtQuick.Controls 2.12 import QtGraphicalEffects 1.0 import QtQuick.Controls 1.4 import QtQuick.Controls.Styles 1.1 Window { visib
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.1
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Calendar {
id: calendar
width: parent.width
height: parent.height
frameVisible: true
weekNumbersVisible: true
// selectedDate: new Date(2014, 0, 1)
focus: true
property var startDate: undefined
property var stopDate: undefined
style: CalendarStyle {
dayDelegate: Item {
readonly property color sameMonthDateTextColor: "#444"
readonly property color selectedDateColor: "#3778d0"
readonly property color selectedDateTextColor: "white"
readonly property color differentMonthDateTextColor: "#bbb"
readonly property color invalidDatecolor: "#dddddd"
property var dateOnFocus: styleData.date
Rectangle {
anchors.fill: parent
border.color: "transparent"
color: styleData.date !== undefined && styleData.selected ? selectedDateColor : "transparent"
}
Rectangle{
id:fl
anchors.fill: parent
property bool flag: false
color: ((dateOnFocus>calendar.startDate) && (dateOnFocus< calendar.stopDate))?"#55555555":
(calendar.startDate !==undefined && dateOnFocus.getTime()===calendar.startDate.getTime())?"#3778d0":"transparent"
}
MouseArea{
anchors.fill: parent
propagateComposedEvents: true
onPressed: {
if(calendar.startDate===undefined){
calendar.startDate=styleData.date
}
else if(calendar.stopDate=== undefined){
calendar.stopDate=styleData.date
}
else{
calendar.startDate=styleData.date
calendar.stopDate= undefined
}
if(calendar.stopDate<=calendar.startDate){
calendar.startDate=styleData.date
calendar.stopDate= undefined
}
mouse.accepted = false
}
}
Label {
id: dayDelegateText
text: styleData.date.getDate()
anchors.centerIn: parent
color: {
var color = invalidDatecolor;
if (styleData.valid) {
// Date is within the valid range.
color = styleData.visibleMonth ? sameMonthDateTextColor : differentMonthDateTextColor;
if (styleData.selected) {
color = selectedDateTextColor;
}
else if (dateOnFocus.getTime()===calendar.startDate.getTime()) {
color = selectedDateTextColor;
}
}
color;
}
}
}
}
}
}
导入QtQuick 2.12
导入QtQuick.Window 2.12
导入QtQuick.Controls 2.12
导入QtGraphicalEffects 1.0
导入QtQuick.Controls 1.4
导入QtQuick.Controls.Styles 1.1
窗口{
可见:正确
宽度:640
身高:480
标题:qsTr(“你好世界”)
历法{
id:日历
宽度:parent.width
高度:parent.height
frameVisible:正确
weekNumbersVisible:真
//选定日期:新日期(2014年0月1日)
焦点:正确
属性变量startDate:未定义
属性变量stopDate:未定义
样式:日历样式{
Day代表:项目{
只读属性颜色sameMonthDateTextColor:#444
只读属性颜色selectedDateColor:#3778d0
只读属性颜色selectedDateTextColor:“白色”
只读属性颜色差异MonthDateTextColor:#bbb
只读属性颜色invalidDatecolor:#dddddd
属性变量dateOnFocus:styleData.date
长方形{
锚定。填充:父级
border.color:“透明”
颜色:styleData.date!==未定义和&styleData.selected?selectedDateColor:“透明”
}
长方形{
id:fl
锚定。填充:父级
属性布尔标志:false
颜色:((dateOnFocus>calendar.startDate)和&(dateOnFocus 如果(calendar.stopDate)可以用QML实现,是的。你有更具体的问题吗?我想知道编码它的方法非常感谢!!!它工作得非常好