Results 1 to 10 of 10

Thread: get Tumbler value - howto

  1. #1
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question get Tumbler value - howto

    I have following Tumbler defined in main.qml:
    Qt Code:
    1. Tumbler
    2. {
    3. id: ueLoginKeypadTumbler
    4.  
    5. Layout.fillWidth: true
    6. Layout.fillHeight: false
    7.  
    8. height: 100
    9.  
    10. antialiasing: true
    11.  
    12. TumblerColumn
    13. {
    14. id: ueNumericTumblerColumnDigit1000
    15.  
    16. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    17. } // ueNumericTumblerColumnDigit1000
    18.  
    19. TumblerColumn
    20. {
    21. id: ueNumericTumblerColumnDigit100
    22.  
    23. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    24. } // ueNumericTumblerColumnDigit100
    25.  
    26. TumblerColumn
    27. {
    28. id: ueNumericTumblerColumnDigit10
    29.  
    30. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    31. } // ueNumericTumblerColumnDigit10
    32.  
    33. TumblerColumn
    34. {
    35. id: ueNumericTumblerColumnDigit1
    36.  
    37. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    38. } // ueNumericTumblerColumnDigit1
    39. } // ueLoginKeypadTumbler
    To copy to clipboard, switch view to plain text mode 
    I also have some Button:
    Qt Code:
    1. Button
    2. {
    3. id: ueButtonLogin
    4.  
    5. Layout.fillWidth: true
    6.  
    7. text: qsTr("Login")
    8.  
    9. onClicked:
    10. {
    11. var uePinCode=ueNumericTumblerColumnDigit1000.model*1000+
    12. ueNumericTumblerColumnDigit100.model*100+
    13. ueNumericTumblerColumnDigit100.model*10+
    14. ueNumericTumblerColumnDigit100.model
    15. print(uePinCode)
    16. } // onClicked - gather Tumbler value
    17. } // ueButtonLogin
    To copy to clipboard, switch view to plain text mode 
    How do I get value of Tumbler in Button's onClicked:?
    Sincerely,
    Marko
    Qt 5.3 Opensource & Creator 3.1.2

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

    Default Re: get Tumbler value - howto

    Aside from the id problem, are you sure JavaScript defines this * operator for arrays that you are using?

    From the look of it this could be a numerical lock, where if of these TumblerColumns is one digit.
    If so, why calculate the resulting value outside of the component?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Re: get Tumbler value - howto

    Ok, I've changed functionality of Button to:
    Qt Code:
    1. Button
    2. {
    3. id: ueButtonLogin
    4.  
    5. Layout.fillWidth: true
    6.  
    7. text: qsTr("Login")
    8.  
    9. onClicked:
    10. {
    11. var uePinCode=0;
    12.  
    13. for(var index=0; index<ueLoginKeypadTumbler.columnCount; index++)
    14. {
    15. uePinCode+=ueLoginKeypadTumbler.getColumn(index)*Math.pow(10, index)
    16. } // for
    17.  
    18. print(uePinCode)
    19. } // onClicked - gather Tumbler value
    20. } // ueButtonLogin
    To copy to clipboard, switch view to plain text mode 
    How do I get selected value form TumblerColumn?

    P.S.: I am very aware that this question is candidate for very stupid question, sorry!

    Sincerely,
    Marko
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: get Tumbler value - howto

    Quote Originally Posted by MarkoSan View Post
    How do I get selected value form TumblerColumn?
    You haven't posted TumblerColumn, we have no way of knowing that.

    Also: your original code suggests that these TumblerColumns have an associated power of 10 already by positioning.
    So the question is: why does the button calculate that instead of Tumbler?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Lightbulb [SOLVED]Re: get Tumbler value - howto

    Quote Originally Posted by anda_skoa View Post
    Aside from the id problem, are you sure JavaScript defines this * operator for arrays that you are using?

    From the look of it this could be a numerical lock, where if of these TumblerColumns is one digit.
    If so, why calculate the resulting value outside of the component?

    Cheers,
    _
    I've managed to complete task on my own. Here is Tumbler:
    Qt Code:
    1. Tumbler
    2. {
    3. id: ueLoginKeypadTumbler
    4.  
    5. Layout.fillWidth: true
    6. Layout.fillHeight: false
    7.  
    8. height: 100
    9.  
    10. antialiasing: true
    11.  
    12. TumblerColumn
    13. {
    14. id: ueNumericTumblerColumnDigit1000
    15.  
    16. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    17. } // ueNumericTumblerColumnDigit1000
    18.  
    19. TumblerColumn
    20. {
    21. id: ueNumericTumblerColumnDigit100
    22.  
    23. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    24. } // ueNumericTumblerColumnDigit100
    25.  
    26. TumblerColumn
    27. {
    28. id: ueNumericTumblerColumnDigit10
    29.  
    30. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    31. } // ueNumericTumblerColumnDigit10
    32.  
    33. TumblerColumn
    34. {
    35. id: ueNumericTumblerColumnDigit1
    36.  
    37. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    38. } // ueNumericTumblerColumnDigit1
    39. } // ueLoginKeypadTumbler
    To copy to clipboard, switch view to plain text mode 
    and here is Button code:
    Qt Code:
    1. Button
    2. {
    3. id: ueButtonLogin
    4.  
    5. Layout.fillWidth: true
    6.  
    7. text: qsTr("Login")
    8.  
    9. onClicked:
    10. {
    11. var uePinCode=0;
    12.  
    13. for(var index=0; index<ueLoginKeypadTumbler.columnCount; index++)
    14. {
    15. uePinCode+=ueLoginKeypadTumbler.getColumn(index).currentIndex*Math.pow(10,
    16. (ueLoginKeypadTumbler.columnCount-index-1));
    17. // print("Index: "+index+" | value: " +ueLoginKeypadTumbler.getColumn(index).currentIndex + " | uePinCode: " + uePinCode);
    18. } // for
    19.  
    20. // print(uePinCode);
    21. } // onClicked - gather Tumbler value
    22. } // ueButtonLogin
    To copy to clipboard, switch view to plain text mode 
    Sincerely,
    Marko
    Qt 5.3 Opensource & Creator 3.1.2

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [SOLVED]Re: get Tumbler value - howto

    Ok :-)

    Overly complicated and awfully non-declarative though

    Cheers,
    _

  7. #7
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [SOLVED]Re: get Tumbler value - howto

    LOL, how would you simplify it?
    Qt 5.3 Opensource & Creator 3.1.2

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

    Default Re: [SOLVED]Re: get Tumbler value - howto

    Each of those TumblerColumn (whatever that element is) has a "weight" associated, right?
    So its "value" is that weight multiplied with the value it shows.

    The "code" you have is then simply the sum of these values.

    Since you did not show the TumblerColumn element, we'll have to make due with part of the ugly code and use currentIndex.

    Qt Code:
    1. TumblerColumn
    2. {
    3. id: ueNumericTumblerColumnDigit1000
    4.  
    5. readonly property int value: currentIndex * 1000
    6.  
    7. model: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    8. } // ueNumericTumblerColumnDigit1000
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Tumbler {
    2. id: ueLoginKeypadTumbler
    3.  
    4. readonly property int code: ueNumericTumblerColumnDigit1000.value + ....
    5. }
    6.  
    7. Button {
    8. onClicked: print(ueLoginKeypadTumbler.code)
    9. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  9. The following user says thank you to anda_skoa for this useful post:

    MarkoSan (2nd September 2015)

  10. #9
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: [SOLVED]Re: get Tumbler value - howto

    AAA, nice job, thanks! And also, I DID show ThumblerColumn in my previous post, but this is not an issue, what I am asking, could I setup these 4 TumblerColumns with QML Repeater?
    Qt 5.3 Opensource & Creator 3.1.2

  11. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [SOLVED]Re: get Tumbler value - howto

    Quote Originally Posted by MarkoSan View Post
    And also, I DID show ThumblerColumn in my previous post
    I am not sure which post you are referring to but it was definitely not part of this thread.
    If you posted it in another thread you could post a link when I asked in this thread, we can't just hunt down all your threads and check if you posted the required information there.

    Quote Originally Posted by MarkoSan View Post
    could I setup these 4 TumblerColumns with QML Repeater?
    Yes.
    Will require some not so nice imperative JavaScript code to update the code property though. Or a C++ model, though that might be a bit of an overkill here.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 30th July 2010, 08:23
  2. Howto: Qt and RSA crypto
    By jonks in forum Qt Programming
    Replies: 15
    Last Post: 21st April 2010, 16:15
  3. Howto use Qt with Boost ?
    By bilgenratte in forum Qt Programming
    Replies: 3
    Last Post: 1st October 2009, 15:12
  4. HowTo Debug
    By SenSej in forum Newbie
    Replies: 0
    Last Post: 17th October 2008, 13:45
  5. QTreeWidgetItemIterator howto
    By seneca in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2006, 09:26

Tags for this Thread

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.