Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Changing first day of week in DayOfWeekRow
Forum Updated to NodeBB v4.3 + New Features

Changing first day of week in DayOfWeekRow

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 982 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amir Afendin
    wrote on 29 Mar 2017, 04:47 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on 29 Mar 2017, 14:55 last edited by
      #2

      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
              }
          }
      
      }
      
      A 1 Reply Last reply 31 Mar 2017, 05:04
      2
      • ? A Former User
        29 Mar 2017, 14:55

        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
                }
            }
        
        }
        
        A Offline
        A Offline
        Amir Afendin
        wrote on 31 Mar 2017, 05:04 last edited by
        #3

        @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.

        1 Reply Last reply
        0

        2/3

        29 Mar 2017, 14:55

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved