Results 1 to 12 of 12

Thread: ComboBox Model inside Listview

  1. #1
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default ComboBox Model inside Listview

    Hi forum

    I'm trying to use ComboBox inside Listview. I can't access to ComboBox model outside Listview

    Qt Code:
    1. Window {
    2. visible: true
    3.  
    4. //...
    5.  
    6. Button {
    7. text: qsTr("Connect")
    8. onClicked:{
    9. apeWindowCmpst.visible = true
    10.  
    11. var code = "90"
    12. var label = "doc"
    13. console.log("code : "+code+" - label : "+label)
    14. listAddApeCmpst.model.append({ "code":code ,
    15. "libelle":label
    16. });
    17.  
    18. modelAPECmpst.append({"name":code}) // can't acces to modelAPECmpst
    19.  
    20. }
    21. }
    22.  
    23. Window {
    24. id:apeWindowCmpst
    25. ...
    26.  
    27.  
    28. ListView{
    29. id:listAddApeCmpst
    30. model: addApeModelCmpst
    31. ...
    32.  
    33. delegate:
    34. Rectangle {
    35. id :rectApeCmpst
    36. ...
    37.  
    38. Item{
    39. id: itmCmpst
    40. anchors.left: parent.left
    41. anchors.leftMargin: 10
    42. height: parent.height-100
    43. width: parent.width-50
    44. Grid{
    45. id:gridAPEActCmpst
    46. anchors.fill: parent
    47. ...
    48.  
    49. ListModel {
    50. id: modelAPECmpst
    51. }
    52. ComboBox{
    53. id:pApeListCmpst
    54. editable: true
    55. width: listAddApeCmpst.width/3*2-36
    56. height: 33
    57. textRole: "name"
    58. model: modelAPECmpst
    59. ...
    60.  
    61. }
    62. ListModel {
    63. id: modelLabelAPECmpst
    64. }
    65. ComboBox{
    66. id:pLabelApeListCmpst
    67. editable: true
    68. width: listAddApeCmpst.width/3*2-36
    69. height: 40
    70. textRole: "name"
    71. model: modelLabelAPECmpst
    72. ...
    73. }
    74.  
    75. }
    76. }
    77. }
    78. }
    79. ListModel {
    80. id: addApeModelCmpst
    81. }
    82. }
    83.  
    84. }
    To copy to clipboard, switch view to plain text mode 

    >> delagate is a dynamic structure

    I want to display values in ComboBox ??

    Screenshot from 2016-10-21 12:11:58.png

    Regards;

  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: ComboBox Model inside Listview

    Each listview delagate has its own, two, local models.

    They are only accessible inside that delegate.

    Do you need individual models per listview delegate?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox Model inside Listview

    Hii,

    My purpose is to set the data in the ComboBox.

    I get the data from BD , in this example :
    Qt Code:
    1. var code = "90"
    2. var label = "doc"
    3. console.log("code : "+code+" - label : "+label)
    4. listAddApeCmpst.model.append({ "code":code ,
    5. "libelle":label
    6. });
    7.  
    8. modelAPECmpst.append({"name":code}) // can't acces to modelAPECmpst
    To copy to clipboard, switch view to plain text mode 

    I tried to use children property, but in vain !!

    Other question why listview model doesn't set values in Combobox :
    Qt Code:
    1. listAddApeCmpst.model.append({ "code":code ,
    2. "libelle":label
    3. });
    To copy to clipboard, switch view to plain text mode 

    Regards,

  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: ComboBox Model inside Listview

    If I repeat my question, is it likely that you'll answer it or is it more likely that you write something else out of context again?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox Model inside Listview

    @anda_skao
    Yes, individual models per listview delegate

    Regards,

  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: ComboBox Model inside Listview

    Quote Originally Posted by Binary01 View Post
    @anda_skao
    Yes, individual models per listview delegate
    See, wasn't that hard

    Since you need to access the individual models from outside the delegate, they need to be defined outside the delegates.

    E.g. a lists of models, or having the combobox models as roles of the main model

    Cheers,
    _

  7. #7
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox Model inside Listview

    No, combobox's models should be inside the delagate, if they was outside delegate = other result

    Regards,

  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: ComboBox Model inside Listview

    Quote Originally Posted by Binary01 View Post
    No, combobox's models should be inside the delagate, if they was outside delegate = other result
    Ok, I am curious: how would that affect the result?

    Cheers,
    _

  9. #9
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox Model inside Listview

    I have an other button in my window, that adds (onClicked) an other delegate (rectangle) in Listview.
    Combobox are editable, if I change a value in a delegate, the others take the same value.

    Regards

  10. #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: ComboBox Model inside Listview

    Quote Originally Posted by Binary01 View Post
    Combobox are editable, if I change a value in a delegate, the others take the same value.
    Now I am confused.
    This sounds like you want the combobox models to be the same, not independent.

    In comment #5 you claimed that the combobox models would need to be different.

    Which one is it?

    Cheers,
    _

  11. #11
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: ComboBox Model inside Listview

    Quote Originally Posted by Binary01 View Post
    Combobox are editable, if I change a value in a delegate, the others take the same value.

    Regards
    This comment for explain why the models should be outside the delegate

    >> The combobox models would need to be different (independent)

    Regards,

  12. #12
    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: ComboBox Model inside Listview

    Quote Originally Posted by Binary01 View Post
    This comment for explain why the models should be outside the delegate
    That is what I suggested in comment #6 to which you replied with a claim that this would result in different behavior.
    When I ask why you think that is you reply with a comment suggesting to share a model across comboboxes?

    Please clarify whether the comboxes are independent or not and separately why you think that having the models instantiated outside the delegates would somehow change behavior.

    Cheers,
    _

Similar Threads

  1. QML/C++ Master/Detail ComboBox/Listview
    By lqsa in forum Qt Quick
    Replies: 3
    Last Post: 20th July 2016, 14:19
  2. Listview inside repeater - model
    By Qmyo in forum Qt Quick
    Replies: 1
    Last Post: 17th May 2016, 16:24
  3. ListView problem with c++ model
    By nick85 in forum Qt Quick
    Replies: 7
    Last Post: 12th September 2013, 09:33
  4. ListView inside another element
    By Dp0H in forum Qt Quick
    Replies: 0
    Last Post: 24th September 2012, 12:44
  5. How to set custom height for ListView & ComboBox items
    By rawfool in forum Qt Programming
    Replies: 1
    Last Post: 30th September 2011, 10:39

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.