【发布时间】:2021-02-27 21:21:07
【问题描述】:
我正在尝试为自己编写一个桌面小部件,即一个日历,它可以将我的大学日历整齐地显示为一种时间表。我在 Kubuntu 20.04 上,所以我想我必须使用 QML...实现逻辑。
基本上,我想从在线 iCal 获取数据,对其进行解析并将其显示在我的小部件中(并且大约每小时更新一次)。我想我可以为第一部分编写一个 python 脚本,但我仍然没有丝毫线索如何实现在 QML 小部件中显示日期(因为 QML 可能只应该处理图形,但我该如何实现那么逻辑呢?)。我已经在网上搜索了很长时间,并查看了很多预装的小部件,但这并没有太大帮助。所有这些也只是用 QML 编写的,据我所知没有 C++……那我该怎么做呢?
编辑:按逻辑我的意思是:我如何表达类似“如果星期一 15:30 有日历条目,则在小部件中的适当位置构造一个矩形并给它一个合适的标签”
到目前为止我的代码:
import QtQuick 2.0
import QtQuick.Layouts 1.0
import org.kde.plasma.components 3.0 as PlasmaComponents
RowLayout {
spacing: 0
Layout.preferredWidth: 640 * units.devicePixelRatio
Layout.preferredHeight: 480 * units.devicePixelRatio
Rectangle {
//day header
Rectangle {
PlasmaComponents.Label {
text: "Monday"
width: parent.width
horizontalAlignment: Text.AlignHCenter
height: parent.height
verticalAlignment: Text.AlignVCenter
}
color: "transparent"
border.color: "#000"
border.width: 1
anchors.top: parent.top
anchors.right: parent.right
width: parent.width
height: parent.height / 12
}
//day body
color: "transparent"
border.color: "#000"
border.width: 1
Layout.fillHeight: true
Layout.fillWidth: true
}
Rectangle {
//day header
Rectangle {
PlasmaComponents.Label {
text: "Tuesday"
width: parent.width
horizontalAlignment: Text.AlignHCenter
height: parent.height
verticalAlignment: Text.AlignVCenter
}
color: "transparent"
border.color: "#000"
border.width: 1
anchors.top: parent.top
anchors.right: parent.right
width: parent.width
height: parent.height / 12
}
//day body
color: "transparent"
border.color: "#000"
border.width: 1
Layout.fillHeight: true
Layout.fillWidth: true
}
Rectangle {
//day header
Rectangle {
PlasmaComponents.Label {
text: "Wednesday"
width: parent.width
horizontalAlignment: Text.AlignHCenter
height: parent.height
verticalAlignment: Text.AlignVCenter
}
color: "transparent"
border.color: "#000"
border.width: 1
anchors.top: parent.top
anchors.right: parent.right
width: parent.width
height: parent.height / 12
}
//day body
color: "transparent"
border.color: "#000"
border.width: 1
Layout.fillHeight: true
Layout.fillWidth: true
}
Rectangle {
//day header
Rectangle {
PlasmaComponents.Label {
text: "Thursday"
width: parent.width
horizontalAlignment: Text.AlignHCenter
height: parent.height
verticalAlignment: Text.AlignVCenter
}
color: "transparent"
border.color: "#000"
border.width: 1
anchors.top: parent.top
anchors.right: parent.right
width: parent.width
height: parent.height / 12
}
//day body
color: "transparent"
border.color: "#000"
border.width: 1
Layout.fillHeight: true
Layout.fillWidth: true
}
Rectangle {
//day header
Rectangle {
PlasmaComponents.Label {
text: "Friday"
width: parent.width
horizontalAlignment: Text.AlignHCenter
height: parent.height
verticalAlignment: Text.AlignVCenter
}
color: "transparent"
border.color: "#000"
border.width: 1
anchors.top: parent.top
anchors.right: parent.right
width: parent.width
height: parent.height / 12
}
//day body
color: "transparent"
border.color: "#000"
border.width: 1
Layout.fillHeight: true
Layout.fillWidth: true
}
}
【问题讨论】:
-
QML 是 Javascript 的一种子集,因此您可以在纯 QML 中创建您的逻辑。另一种选择是使用 C++ 扩展 QML。从您的问题中不清楚您的逻辑是什么意思。请用更多信息更新您的问题。
-
你不知道具体怎么做?你所说的“逻辑”是什么意思? QML 是基于 javascript 的,所以它可以做大部分 javascript 可以做的事情。您引用的页面上有示例-您是否已阅读并了解它们的工作原理?您所说的“iCal”是指 RFC5545 数据格式、Apple 日历应用程序、TCL/Tk“ical”包还是某种日历网站?你的网络服务器有什么样的 API 和数据格式?一般情况下,数据可以通过
XmlHttpRequest()下载,即使不是XML或者HTTP,然后用XML/JSON解析器或者写一行一行的字符串解析器进行解析。
标签: qt qml kde-plasma