Changing first day of week in DayOfWeekRow
Solved
QML and Qt Quick
-
I haven't found here this option. Yes I know about "locale", but i want name of days stay in local language but change just first day to Sunday.
-
Hi! If you look at the sources of
DayOfWeekRow
(here) , you'll see that there is no chance to get what you want. But you can build your own item in two minutes:main.qml
import QtQuick 2.7 import QtQml 2.2 import QtQuick.Controls 2.1 import QtQuick.Layouts 1.1 ApplicationWindow { visible: true width: 640 height: 480 MyDayOfWeekRow { backgroundColor: "skyblue" } }
MyDayOfWeekRow.qml
import QtQuick 2.7 import QtQml 2.2 import QtQuick.Controls 2.1 import QtQuick.Layouts 1.1 Item { implicitWidth: row.implicitWidth implicitHeight: row.implicitHeight property int format: Locale.ShortFormat property color backgroundColor: "orange" property color textColor: "black" property real rightPadding: 6 property real topPadding: 6 property real leftPadding: 6 property real bottomPadding: 6 property real spacing: 6 // --- private --- id: control function getStandaloneDayName(d) { return Qt.locale().standaloneDayName(d, control.format) // use default locale } Component { id: itemDelegate Text { text: getStandaloneDayName(model.index) font.bold: true color: control.textColor horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } } Rectangle { id: background anchors.fill: parent color: control.backgroundColor } Row { id: row rightPadding: control.rightPadding topPadding: control.topPadding leftPadding: control.leftPadding bottomPadding: control.bottomPadding spacing: control.spacing Repeater { model: 7 // starts with Locale.Sunday = 0 delegate: itemDelegate } } }
-
Hi! If you look at the sources of
DayOfWeekRow
(here) , you'll see that there is no chance to get what you want. But you can build your own item in two minutes:main.qml
import QtQuick 2.7 import QtQml 2.2 import QtQuick.Controls 2.1 import QtQuick.Layouts 1.1 ApplicationWindow { visible: true width: 640 height: 480 MyDayOfWeekRow { backgroundColor: "skyblue" } }
MyDayOfWeekRow.qml
import QtQuick 2.7 import QtQml 2.2 import QtQuick.Controls 2.1 import QtQuick.Layouts 1.1 Item { implicitWidth: row.implicitWidth implicitHeight: row.implicitHeight property int format: Locale.ShortFormat property color backgroundColor: "orange" property color textColor: "black" property real rightPadding: 6 property real topPadding: 6 property real leftPadding: 6 property real bottomPadding: 6 property real spacing: 6 // --- private --- id: control function getStandaloneDayName(d) { return Qt.locale().standaloneDayName(d, control.format) // use default locale } Component { id: itemDelegate Text { text: getStandaloneDayName(model.index) font.bold: true color: control.textColor horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter } } Rectangle { id: background anchors.fill: parent color: control.backgroundColor } Row { id: row rightPadding: control.rightPadding topPadding: control.topPadding leftPadding: control.leftPadding bottomPadding: control.bottomPadding spacing: control.spacing Repeater { model: 7 // starts with Locale.Sunday = 0 delegate: itemDelegate } } }
@Wieland solved just adding
delegate: Text { text: { if (globalModel.isSundayFirst) Qt.locale().dayName(model.day === 0 ? 6 : model.day - 1, Locale.ShortFormat) else { Qt.locale().dayName(model.day, Locale.ShortFormat) } } horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter }
to default DayOfWeekRow like said here . But man, thank you so much for Qt.locale() function, i was struggling for hours figuring out why Qt.dayName() doesn't want to work. Nobel Prize for you brother.