QML 日历不显示工作日或月份年份(但它似乎确实存在......)

QML Calendar not showing week day or month year (however it does seem to be there....)

我使用的是 Qt 5.13,一般来说 Qt.Controls2,但是日历只存在于 v1.0 或实验室版本中(我无法开始工作,所以使用 V1)。

我的密码是

import QtQuick 2.2
import QtQuick.Controls 1.4 as Old

import Tree 1.0
import "."

ApplicationWindow {
    id: window
    width: 800; height: 1000
    title: "TreeView Example"
    visible: true
    Old.Calendar {
        anchors.centerIn: parent
        id: calendar
    }
}

然而,当我这样做时,我没有看到星期几,也没有在导航栏中看到 month/year,尽管我可以看到它们应该在哪里:

我尝试添加一个 navigationBar 委托,但是这样就去掉了导航箭头。

style: CalendarStyle {
  navigationBar: Text {
    text: "hello"
  }
}

那么,如何获得导航箭头、显示 month/year 和星期几?文档似乎建议我开箱即用...... 现在......我想我可以添加下拉列表作为选择 month/year 并将它们放在导航栏中的解决方案......但是当我这样做时我实际上可以看到星期几在那里,只是他们的文字颜色是白色的,所以我觉得我错过了关于导航栏的技巧...?

我也在使用 Qt 5.13.0 并试过你的例子。删除一些导入后,它正在处理以下文件:

main.qml

import QtQuick 2.2
import QtQuick.Controls 1.4 as Old
import QtQuick.Controls 2.12

ApplicationWindow {
    id: window
    width: 800; height: 1000
    title: "TreeView Example"
    visible: true
    Old.Calendar {
        anchors.centerIn: parent
        id: calendar
    }
}

main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char* argv[])
{
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    QQmlContext* context = engine.rootContext();

    engine.load(QUrl("./data/main.qml"));
    return app.exec();
}

我将获得以下内容:

我建议您尝试我的代码并将其与您的应用程序进行比较。

值得阅读对@Aleph0 的评论的回应 post,但为了让它工作,我必须复制默认样式并将它们放在我的元素中。最终代码(去掉与日历无关的部分)看起来像

import QtQuick.Controls 2.4
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.3
import QtQuick 2.2
import QtQuick.Controls 1.4 as Old
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls.Private 1.0

ApplicationWindow {
  id: window
  width: 300; height: 300
  title: "Calendar Example"
  visible: true
  ColumnLayout {
      anchors.fill: parent
    Old.Calendar {
      id: calendar
      style: CalendarStyle {
          gridVisible: true
      dayOfWeekDelegate: Rectangle {
          color: gridVisible ? "#fcfcfc" : "transparent"
          implicitHeight: Math.round(TextSingleton.implicitHeight * 2.25)
          Label {
              text: control.locale.dayName(styleData.dayOfWeek, control.dayOfWeekFormat)
              anchors.centerIn: parent
          }
      }
        navigationBar: Rectangle {
          height: Math.round(TextSingleton.implicitHeight * 2.73)
          color: "#f9f9f9"

          Rectangle {
              color: Qt.rgba(1,1,1,0.6)
              height: 1
              width: parent.width
          }

          Rectangle {
              anchors.bottom: parent.bottom
              height: 1
              width: parent.width
              color: "#ddd"
          }

          HoverButton {
              id: previousMonth
              width: parent.height
              height: width
              anchors.verticalCenter: parent.verticalCenter
              anchors.left: parent.left
              source: "./assets/leftanglearrow.png"
              onClicked: control.showPreviousMonth()
          }
          Label {
              id: dateText
              text: styleData.title
              elide: Text.ElideRight
              horizontalAlignment: Text.AlignHCenter
              font.pixelSize: TextSingleton.implicitHeight * 1.25
              anchors.verticalCenter: parent.verticalCenter
              anchors.left: previousMonth.right
              anchors.leftMargin: 2
              anchors.right: nextMonth.left
              anchors.rightMargin: 2
          }
          HoverButton {
              id: nextMonth
              width: parent.height
              height: width
              anchors.verticalCenter: parent.verticalCenter
              anchors.right: parent.right
              source: "./assets/rightanglearrow.png"
              onClicked: control.showNextMonth()
          }
        } 
      }
    }
  }
}

结果是

在理想情况下,可以选择 a) 使用 Private 控件,因为我使用的似乎是 Qt 内部模块,但通过使用带有鼠标区域的图像可以轻松修复,如果我也不必使用任何 1.x 控件,但似乎没有 2.x 以图形方式显示日期等的方式。无论如何,希望这对某人有用 - 它是实际上是默认样式的复制粘贴工作,因此可以简化很多...