Results 1 to 3 of 3

Thread: How to get the current date out of a Date Tumbler

  1. #1
    Join Date
    Aug 2019
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default How to get the current date out of a Date Tumbler

    Hello All,

    I am a newbie in QML and I am trying to set the time through a Tumbler. The code for the Tumbler is
    Qt Code:
    1. import QtQuick 2.12
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 2.12
    4.  
    5. Rectangle {
    6. width: frame.implicitWidth + 10
    7. height: frame.implicitHeight + 10
    8.  
    9. function formatText(count, modelData) {
    10. var data = count === 12 ? modelData + 1 : modelData;
    11. return data.toString().length < 2 ? "0" + data : data;
    12. }
    13.  
    14. FontMetrics {
    15. id: fontMetrics
    16. }
    17.  
    18. Component {
    19. id: delegateComponent
    20.  
    21. Label {
    22. text: formatText(Tumbler.tumbler.count, modelData)
    23. opacity: 1.0 - Math.abs(Tumbler.displacement) / (Tumbler.tumbler.visibleItemCount / 2)
    24. horizontalAlignment: Text.AlignHCenter
    25. verticalAlignment: Text.AlignVCenter
    26. font.pixelSize: fontMetrics.font.pixelSize * 1.25
    27. }
    28. }
    29.  
    30. Frame {
    31. id: frame
    32. padding: 0
    33. anchors.centerIn: parent
    34.  
    35. Row {
    36. id: row
    37.  
    38. Tumbler {
    39. id: hoursTumbler
    40. model: 12
    41. delegate: delegateComponent
    42. }
    43.  
    44. Tumbler {
    45. id: minutesTumbler
    46. model: 60
    47. delegate: delegateComponent
    48. }
    49.  
    50. Tumbler {
    51. id: amPmTumbler
    52. model: ["AM", "PM"]
    53. delegate: delegateComponent
    54. }
    55. }
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 

    I am calling the time tumbler from another page
    Qt Code:
    1. import QtQuick 2.9
    2. import QtQuick.Window 2.2
    3. import QtQuick.Controls 2.0
    4. import QtQuick.Particles 2.0
    5. import QtQuick.Layouts 1.0
    6. import QtQuick.Controls 1.3
    7. import Timebar 3.14
    8. //import "ChangeLanguageAndRegion.qml"
    9.  
    10.  
    11. Window {
    12. id: changedateandtime
    13. visible: true
    14. visibility: Window.FullScreen
    15. color: "#000000"
    16.  
    17. Item {
    18. id: timeChangeTumbler_item
    19. anchors.horizontalCenter: parent.horizontalCenter
    20. anchors.horizontalCenterOffset: -40
    21. anchors.verticalCenter: parent.verticalCenter
    22. anchors.verticalCenterOffset: 30
    23. height: 200
    24. width: 180
    25.  
    26. TimeTumbler {
    27. id: timeTumbler
    28. anchors.rightMargin: 0
    29. anchors.bottomMargin: -1
    30. anchors.leftMargin: 0
    31. anchors.topMargin: 1
    32. // border.width: 0
    33. }
    34. }
    35. Item {
    36. id: doneandcancel
    37. anchors.horizontalCenter: parent.horizontalCenter
    38. y: 420
    39. width: 120
    40. height: 50
    41.  
    42. Image {
    43. id: donetickmark
    44. anchors.left: parent.left
    45. anchors.top: parent.top
    46. anchors.bottom: parent.bottom
    47. width: parent.width/3
    48. fillMode: Image.PreserveAspectFit
    49. source: "resources/TickmarkIcon.png"
    50. }
    51. Button {
    52. id: donebutton
    53. anchors.left: passkey.left
    54. anchors.right: passkey.right
    55. anchors.bottom: passkey.bottom
    56. anchors.top: passkey.top
    57. anchors.topMargin: -20
    58. anchors.leftMargin: -20
    59. opacity: 0
    60.  
    61. onClicked: {
    62. //save changes
    63. var hour = timeTumbler.currentIndex;
    64. mainLoader.source = 'Dashboard_2.qml';
    65. }
    66. }
    67.  
    68. Image {
    69. id: cancelcross
    70. anchors.right: parent.right
    71. anchors.top: parent.top
    72. anchors.bottom: parent.bottom
    73. width: parent.width/3
    74. fillMode: Image.PreserveAspectFit
    75. source: "resources/CrossIcon.png"
    76. }
    77. Button {
    78. id: cancelbutton
    79. anchors.left: log.left
    80. anchors.right: log.right
    81. anchors.bottom: log.bottom
    82. anchors.top: log.top
    83. anchors.topMargin: -20
    84. anchors.rightMargin: -20
    85. opacity: 0
    86.  
    87. onClicked: {
    88.  
    89. mainLoader.source = 'Dashboard_2.qml';
    90. }
    91.  
    92. }
    93.  
    94. }
    To copy to clipboard, switch view to plain text mode 
    When I press on the Done button I would like to get the hour from the hour column of the tumbler but I don't get anything. I am using the id : timeTumbler to access it but how can I get to the hours column and retrieve the index ?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to get the current date out of a Date Tumbler

    The internal object of TimeTumbler are not directly addressable from outside, but you can "forward" those properties that you need.

    Qt Code:
    1. Rectangle {
    2. property alias hoursIndex: hoursTumbler.currentIndex
    3.  
    4. Tumbler {
    5. id: hoursTumbler
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    or maybe even more appropriate the hour value
    Qt Code:
    1. Rectangle {
    2. readonly property int hours: hoursTumbler.currentIndex + 1
    3.  
    4. Tumbler {
    5. id: hoursTumbler
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Aug 2019
    Posts
    2
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: How to get the current date out of a Date Tumbler

    Thank you!

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2014, 00:41
  2. Replies: 2
    Last Post: 13th April 2010, 16:50
  3. get date
    By mmm286 in forum Newbie
    Replies: 2
    Last Post: 17th February 2010, 09:18
  4. date
    By AnithaRagupathy in forum Qt Programming
    Replies: 3
    Last Post: 2nd November 2007, 06:28
  5. How to default Date-Edit Widget to system date
    By JohnToddSr in forum Qt Tools
    Replies: 4
    Last Post: 17th January 2007, 19:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.