Results 1 to 2 of 2

Thread: Custom Select implementation

  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Select implementation

    Hi,

    I would like to seek help regarding my implementation of custom select/dropdown the same in ios 8
    a) I created a CustomSelect.qml and CustomSelectItems.qml
    b) I used CustomSelect component in other qml pages

    Page1.qml
    Qt Code:
    1. // the parent of this page has a StackView
    2. Item {
    3.  
    4. Component.onCompleted {
    5. textSelect.setValue("en");
    6. }
    7.  
    8. CustomSelect {
    9. id: textSelect
    10. model: ListModel {
    11. ListElement {
    12. item: "English"
    13. value: "en"
    14. icon: "flag-en.png"
    15. }
    16. ListElement {
    17. item: "German"
    18. value: "de"
    19. icon: "flag-de.png"
    20. }
    21. }
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    CustomSelect.qml
    Qt Code:
    1. //displays the current selected item
    2. Item {
    3. id: select
    4.  
    5. property ListModel model
    6.  
    7. property int currentIndex
    8.  
    9. function setValue(value) {
    10. for (var i=0; i<select.model.count; ++i)
    11. {
    12. if (model.get(i).value === value)
    13. {
    14. select.currentIndex = i;
    15. break;
    16. }
    17. }
    18. }
    19.  
    20. Row {
    21. Image {
    22. id: icon
    23. source: select.model.get(select.currentIndex).icon
    24. }
    25. Text {
    26. id: value
    27. text: select.model.get(select.currentIndex).item
    28. }
    29. }
    30.  
    31. MouseArea {
    32. anchors.fill: parent
    33. onClicked: {
    34. //i want to show the select items page in the entire Page1.qml
    35. }
    36. }
    37. }
    To copy to clipboard, switch view to plain text mode 

    I wanted to push the CustomSelectItems.qml into Page1's parent stack, however i'm not sure if it is possible to get the CustomSelect parent's stackview.
    Determining the CustomSelect parent should be dynamic because it will be used into another pages also with different stackview.

    I tried putting a stackView on CustomSelect and push the CustomSelectItems, however i'm having problem displaying it on top of Page1.

    CustomSelectItems.qml
    Qt Code:
    1. //used to display items from the model
    2. ListView {
    3. id: selectList
    4.  
    5. property alias listModel: selectList.model
    6.  
    7. property alias currentIndex: selectList.currentIndex
    8.  
    9. delegate: Row {
    10. Image {
    11. id: icon
    12. source: model.icon
    13. }
    14. Text {
    15. id: value
    16. text: model.item
    17. }
    18. }
    19. }
    To copy to clipboard, switch view to plain text mode 

    Please advise. I hope my explanation is clear. Thanks.


    Added after 1 32 minutes:


    I tried to create a signal on CustomSelect and used it to push the CustomSelectItems page, however I'm having problem how to return the currentIndex of the list view to update the value of CustomSelect

    Page1.qml
    Qt Code:
    1. Item {
    2.  
    3. Component.onCompleted {
    4. textSelect.setValue("en");
    5. }
    6.  
    7. CustomSelect {
    8. id: textSelect
    9. model: ListModel {
    10. ListElement {
    11. item: "English"
    12. value: "en"
    13. icon: "flag-en.png"
    14. }
    15. ListElement {
    16. item: "German"
    17. value: "de"
    18. icon: "flag-de.png"
    19. }
    20. }
    21.  
    22. onClicked: {
    23. mainStack.push({item:Qt.resolvedUrl("CustomSelectItems.qml"), properties:{listModel: textSelect.model, currentIndex: textSelect.currentIndex}})
    24. }
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by joko; 4th November 2015 at 14:05.

  2. #2
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Custom Select implementation

    Hi Qt Masters,

    Please help me resolve this issue.

    Is there a way to capture the signal coming from popped qml item in a StackView?

    Thanks.

Similar Threads

  1. Replies: 5
    Last Post: 9th June 2014, 16:40
  2. Replies: 7
    Last Post: 27th February 2014, 22:11
  3. Custom SelectionModel implementation needed?
    By graffy in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2014, 04:47
  4. QImageReader with custom QIODevice implementation
    By psih128 in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2011, 03:39
  5. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23

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.