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

I am using Qt 5.13 and in general Qt.Controls 2 however the calendar only exists in v1.0 or the labs version (which I can't get to work, so using V1).
My code is
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
}
}
However when I do this, I don't see the day of the week, nor the month/year in the navivagation bar, although I can see where they should be:
I have tried to add a navigationBar delegate, but this then gets rid of the navigation arrows.
style: CalendarStyle {
navigationBar: Text {
text: "hello"
}
}
So, how do I have the nav arrows, show the month/year and show the days of week? The documentation seems to suggest I would get these out of the box...
Now... I thought I could add drop downs as a work around to choose month/year and place them in the nav bar... however when I do that I can actually see that the days of the week are there, just their text colour is white, so I feel I am missing a trick with regard to the navigation bar...?

Worth reading the comments in response to #Aleph0's post, but to get it working I had to copy the default styles and place them within my element. The final code (stripping out the bits that aren't specifically about the calendar then), looks like
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()
}
}
}
}
}
}
That results in
In an ideal world, there would be an alternative to a) using Private controls as that seems like I am using Qt internal modules, but thats an easy fix by using an Image with a mouse area, and if I didn't have to use any 1.x controls either, but there doesn't seem to be a 2.x way of graphically displaying dates etc. Anyway, hopefully this can be useful to someone - it's literally a copy paste job of the default styling so it can be simplified alot...

I'm also using Qt 5.13.0 and just tried you example. After removing some imports it was working with the following files:
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();
}
I'll obtain the following:
I suggest, that you will try my code and compare it with your application.

I had the same problem - days of week and title were almost invisible, because they were written with white color on light gray background. In my case the problem was in desktop color theme in Ubuntu Studio. After I changed it from Dark to Light the text appeared in black as expected. It seems Qt5 can't handle dark themes well or implementation in Ubuntu Studio (22.04) is buggy. The same was true for text in Button-s.

Related

Qml: Accessibility not working for all elements

I am adding accessibility to QML application. While using Windows Narrator or NVDA program, they are not able to read elements of ComboBox. They read ComboBox fine but not content of it.
Cannot post my project to posting example file here.
QML:
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.14
Item {
visible: true
width: 640
height: 480
ComboBox{
model: ["option1","option2","option3"]
Accessible.name: "ComboBox"
Accessible.description: "ComboBox"
}
}
Main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickView>
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
QQuickView view;
const QUrl url(QStringLiteral("qrc:/main.qml"));
view.setSource(url);
view.show();
return app.exec();
}
Qt Version: 5.15.2, any help is appreciated
So, after browsing QT Bugs found out that QML is not fully supported for accessibility and QT is aware of it since 2016. This ticket is really helpful
https://bugreports.qt.io/browse/QTBUG-68465 and from comments
Qt should actually be setting focus to the menu's first child menu item, since this is thew behavior VoiceOver expects. We currently don't do this.
So by forcing focus this can be fixed, i am able to fix it.
Check focus:true that is most important part.
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
Item {
visible: true
width: 640
height: 480
ComboBox{
id: selectMe
model: ["selectMe1","selectMe2","selectMe3"]
focus: true
Accessible.role: Accessible.ComboBox
contentItem:
Text {
id: ld2
text: selectMe.currentText
}
hoverEnabled: true
popup: Popup {
y: selectMe.height - layoutRowHeight
width: selectMe.width
implicitHeight: contentItem.implicitHeight
padding: 1
focus: true
contentItem: ListView {
spacing: 2
focus: true
Accessible.role: Accessible.List
clip: true
implicitHeight: contentHeight
model: selectMe.popup.visible ? selectMe.delegateModel : null
delegate: ItemDelegate {
id: selectMeDelegate
width: selectMe.width
focus: true
contentItem:
Text {
text: modelData
color: "black"
font.pointSize: 12
elide: Text.ElideRight
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignLeft
focus: true
Accessible.name: "selectMe combobox"
Accessible.description: "selectMe"
}
background: Rectangle{
width: selectMe.width
height: selectMe.height
}
}
}
background: Rectangle {
color:"grey"
opacity: 0.5
radius: 10
}
}
}
}

How to restrict maximum lines of user input in TextEdit in QML

I am currently trying to implement a textedit within a rectangle. The problem is that the user is still able to type beyond the confines of the rectangle. I have set the wrapMode to TextEdit.Wrap, but the problem is that the text from the textedit can spill over from the bottom of the rectangle. I tried to fix this by making clip true, but the user is still able to type characters but not see it. What do I do?
import QtQuick 2.12
import QtQml.Models 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.12
import QtMultimedia 5.0
Rectangle{
anchors{
top: parent.top
topMargin: parent.height/15
left: parent.left
leftMargin: parent.width/15
right: parent.right
rightMargin: parent.width/15
bottom: parent.bottom
bottomMargin: parent.height/1.2
}
color: 'white'
z: 1
radius: 15
TextEdit{
clip: true
cursorPosition: 5
anchors.fill: parent
wrapMode: TextEdit.Wrap
}
}
This is an image of the text with rectangle: clip is not set and wrapMode: TextEdit.Wrap. This image is the opposite of what I want
There is actually no way to limit the maximum number of rows. Theoretically, since this is open source, you can do anything, but it will require some effort. I can suggest a workaround:
Rectangle {
id: container
width: 200
height: 40
anchors.centerIn: parent
color: "orange"
TextEdit {
id: txt
anchors.fill: parent
padding: 3
font.pixelSize: 14
focus: true
wrapMode: TextEdit.Wrap
onTextChanged: {
var pos = txt.positionAt(1, container.height + 1);
if(txt.length >= pos)
{
txt.remove(pos, txt.length);
}
}
}
}
This method just cuts off everything that is found outside of the box.

QML DropShadow sometimes renders badly

I am using QML's inbuilt DropShadow type (import QtGraphicalEffects) to generate a shadow of some rectangles that are contained within an Item. The DropShadow is also a child of said Item. But sometimes the shadow is rendered very badly. I am dynamically creating the screen and adding it to a SwipeView; the code is as follows:
swipeView.addItem(tasksScreen.createObject(swipeView))
swipeView.incrementCurrentIndex()
"tasksScreen" is the screen that the rectangles and DropShadow are part of.
The following video depicts the issue and the code that generates this behavior:
https://yadi.sk/i/mwl_8IZmm_jetQ
I believe the issue is you are making the DropShadow a child of its source - which is creating a looping dependency.
Instead, try making it a sibling of your Item or even better, set it up as your Item's layer.effect.
You can see these different techniques in the DropShadow documentation:
https://doc.qt.io/qt-5/qml-qtgraphicaleffects-dropshadow.html
The problem is the source property in your code you have set the source as the parent item in your code. Give the source as your visual object(Rectangle). I have attached the code for your reference.
import QtQuick 2.9
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Component {
id: swipeviewComponentId
Item {
id: itemId
Rectangle {
id: rectangleId
anchors.fill: parent
anchors.margins: 10
radius: 10
}
DropShadow {
anchors.fill: source
horizontalOffset: 3
verticalOffset: 3
radius: 8.0
samples: 17
color: "#80000000"
source: rectangleId
}
}
}
Column {
anchors.fill: parent
anchors.margins: 10
spacing: 10
SwipeView {
id: swipeViewId
width: parent.width
height: parent.height - addButtonId.height - (2 * parent.spacing) - pageIndicatorId.height
}
PageIndicator {
id: pageIndicatorId
currentIndex: swipeViewId.currentIndex
count: swipeViewId.count
anchors.horizontalCenter: parent.horizontalCenter
}
Button {
id: addButtonId
width: parent.width
height: 40
text: "Add item"
onClicked: {
swipeViewId.addItem(swipeviewComponentId.createObject(swipeViewId,
{height: swipeViewId.height, width: swipeViewId.width}))
swipeViewId.incrementCurrentIndex()
}
}
}
}

QT : render in release differs from debug

I'm having a strange issue with a C++ and QML app which render differently whereas i'm in debug or release :
The debug (left) render is the correct one.
In release (right) the accent colors is wrong and all the fonts are bigger. It's also seems to miss some shadows.
Both builds are done with visual 2015 after complete clean of the solution.
This how my window is set :
MainWindow::MainWindow(QMainWindow * parent) :QMainWindow(parent)
{
QApplication::setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
mQuickWidget = nullptr;
setAttribute(Qt::WA_DeleteOnClose, true);
this->setMinimumSize(640, 480);
mQuickWidget = new QQuickWidget(this);
QQuickStyle::setStyle("Material");
setCentralWidget(mQuickWidget);
this->setWindowTitle("Générateur de licence");
qmlRegisterType<mycompany::Licensor>("com.mycompany.licensor", 1, 0, "Licensor");
mQuickWidget->setSource(QUrl(QStringLiteral("qrc:/main.qml")));
mQuickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
mQuickWidget->setAttribute(Qt::WA_AlwaysStackOnTop);
mQuickWidget->show();
}
And this part of the QML :
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 1.4 as Controls14
import QtQuick.Controls 2.2
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.1
import QtQuick.Layouts 1.3
import QtQuick.Controls.Material 2.1
import com.prynel.licensor 1.0
Item {
Material.theme: Material.Light
Material.accent: Material.DeepPurple
id: base
width : 900
height: 500
function twoDigit(n)
{
return n > 9 ? ""+n : "0"+n;
}
Licensor {
id: licensor
}
TabBar {
id: bar
width: parent.width
anchors.top: parent.top
anchors.left: parent.left
TabButton {
text: qsTr("1. Licence")
}
TabButton {
text: qsTr("2. Presets")
}
TabButton {
text: qsTr("3. Options")
}
TabButton {
text: qsTr("4. Finalisation")
}
}
StackLayout {
width: parent.width
anchors.bottom: parent.bottom
anchors.top: bar.bottom
currentIndex: bar.currentIndex
//LICENCE
Item {
id: licenceTab
Label {
id: labelacti
text: qsTr("Code d'activation :")
anchors.left: parent.left
anchors.leftMargin: 15
anchors.top: parent.top
anchors.topMargin: 35
}
TextField {
id: input_codeacti
anchors.left: parent.left
anchors.leftMargin: 230
anchors.verticalCenter: labelacti.verticalCenter
width: 201
antialiasing: true
placeholderText: qsTr("Code d'activation")
onTextChanged: {rect_result.visible = false;}
}
}
// Lot of other fields
}
Controls14.Calendar {
property var linkedItem
id: calendar
parent: base
visible: false
anchors.verticalCenter: base.verticalCenter
anchors.horizontalCenter: base.horizontalCenter
onClicked:
{
linkedItem.text = base.twoDigit(date.getDate()) + "/" + base.twoDigit((date.getMonth() + 1)) + "/" + base.twoDigit(date.getFullYear());
calendar.visible = false;
}
}
}
I'm not putting everything as there is lot of field which should not be the source of the problems.
What can cause this different result in the UI ?
Maybe are you providing a Qt Quick Controls special configuration file qtquickcontrols2.conf ?
The configuration file is usually embedded into the application's resources, but it can also be located in the directory specified by the environment variable QT_QUICK_CONTROLS_CONF. There are some more environment variables that can affect styles. Look to your QtCreator's project settings and check the environment differences between the Debug and the Release run settings.

How to use QtQuick.Window element in Qt5 and QML?

I recently installed the Qt5 RC2 for Mac OS X and started developing some QML applications. After looking at the new elements, I especially wanted to try the Window and Screen Element. (http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html)
So I set the imports at the top of the file like this:
import QtQuick 2.0
import QtQuick.Window 2.0
The import is found, but I can use neither Window nor Screen. Everytime I type Screen or Window an error appears which says "Unknown component (M300)"
Has anyone an idea what the problem is?
Sometimes QtCreator doesn't recognize some types/properties, mainly the ones that were not present in Qt4.x, but that doesn't mean you can't use them, so yes, 'Window' is unknown just like properties 'antialiasing', 'fontSizeMode' or 'active' are, but you can use them, here is an example of use for QtQuick.Window 2.0 :
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
id: win1;
width: 320;
height: 240;
visible: true;
color: "yellow";
title: "First Window";
Text {
anchors.centerIn: parent;
text: "First Window";
Text {
id: statusText;
text: "second window is " + (win2.visible ? "visible" : "invisible");
anchors.top: parent.bottom;
anchors.horizontalCenter: parent.horizontalCenter;
}
}
MouseArea {
anchors.fill: parent;
onClicked: { win2.visible = !win2.visible; }
}
Window {
id: win2;
width: win1.width;
height: win1.height;
x: win1.x + win1.width;
y: win1.y;
color: "green";
title: "Second Window";
Rectangle {
anchors.fill: parent
anchors.margins: 10
Text {
anchors.centerIn: parent
text: "Second Window"
}
}
}
}
You just need to have a Window item as root object, and you can embed other Window items into it.

Categories

Resources