Witam wszystkich
Mam prosty programik ktory wyswietla godzine i date. Ogolnie wszystko dziala, dopoki nie wylacze daty i ponownie jej nie wlacze. Po tej operacji godzina nie dopasowuje sie automatycznie.
W kodzie zaznaczylem znakami >> i << o ktora pozycje w menu kontekstowym chodzi. Gdzie lezy problem?
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 1.4
//https://doc.qt.io/qt-5/qml-qtqml-date.html
Window
{
id: mainWindow
width: 640
height: 480
visible: true
title: qsTr("QML Clock")
property string czas_string: "Godzina"
property string data_string: "Data"
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
onClicked:
{
if (mouse.button == Qt.RightButton)
{
menu.popup()
// console.log("Prawy")
}
else if (mouse.button == Qt.LeftButton)
{
// console.log("Lewy")
}
else
{
// console.log("Inny")
}
}
Menu
{
id: menu
MenuItem
{
checkable: true
text: qsTr("Usuń obramowanie")
shortcut: "Ctrl+B"
onTriggered:
{
if (checked == true)
{
flags = flags | Qt.FramelessWindowHint
text = "Przywróć obramowanie"
}
else
{
flags = flags & ~Qt.FramelessWindowHint
text = "Usuń obramowanie"
}
}
}
MenuItem
{
id: naWierzchu
checkable: true
text: "Zawsze na wierzchu"
shortcut: "Ctrl+T"
onTriggered:
{
if (checked == true)
{
flags = flags | Qt.WindowStaysOnTopHint
text = "Zawsze na wierzchu"
}
else
{
flags = flags & ~Qt.WindowStaysOnTopHint
text = "Zawsze na wierzchu"
}
}
}
MenuSeparator { }
>>>>>>> MenuItem <<<<<<<<
{
checkable: true
text: "Usun Datę"
// shortcut: "Ctrl+D"
onTriggered:
{
if (checked == true)
{
text = "Usun datę"
dateLabel.visible = false
timeLabel.width = mainWindow.width
timeLabel.height = mainWindow.height
}
else
{
text = "Pokaż datę"
dateLabel.visible = true
timeLabel.width = mainWindow.width
timeLabel.height = mainWindow.height/2
}
}
}
MenuSeparator { }
MenuItem
{
text: "Zamknij progrm"
shortcut: "Ctrl+Q"
onTriggered: Qt.quit()
}
}
}
function timeChanged()
{
var data = new Date;
czas_string = data.toLocaleString(Qt.locale("pl_PL"), "h:mm:ss");
data_string = data.toLocaleString(Qt.locale("pl_PL"), "yyyy-MM-dd\ndddd");
}
Timer
{
interval: 1000; running: true; repeat: true
onTriggered: mainWindow.timeChanged()
}
Text
{
x: 0
y: 0
id: timeLabel
text: qsTr(czas_string)
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
width: mainWindow.width
height: mainWindow.height/2
font.pointSize: 400
minimumPointSize: 8
fontSizeMode: Text.Fit
}
Text
{
x: 0
y: mainWindow.height/2
id: dateLabel
text: qsTr(data_string)
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
width: mainWindow.width
height: mainWindow.height/2
font.pointSize: 400
minimumPointSize: 8
fontSizeMode: Text.Fit
}
}