July 10, 2011

aabc aabc
Robot Herder
257 posts

Is it possible to pass ListModel to ListView with some missing parameters?

 

Is it possible to pass ListModel to ListView with some missing parameters?
Is there a way to write a delegate that uses only the parameters that the model gave it and use default parameters for those who dont?

3 replies

July 11, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

Did you try this out ?? what is the problem you are facing…

July 11, 2011

h3nk3 h3nk3
Lab Rat
13 posts

You should be able to set default parameters in your delegate. So when parameters in your ListModel is not set the delegate shows what you deem to be the default value for them.

July 11, 2011

ngocketit ngocketit
Lab Rat
24 posts
aabc wrote:
Is it possible to pass ListModel to ListView with some missing parameters? Is there a way to write a delegate that uses only the parameters that the model gave it and use default parameters for those who dont?

Yes, you totally can do that. Check the sample below:

  1. ListModel {
  2.         ListElement {
  3.             label: QT_TR_NOOP("Item 1")
  4.             value: "item1"
  5.         }
  6.         ListElement {
  7.             label: QT_TR_NOOP("Item 2")
  8.             value: "item2"
  9.             position: "left"
  10.             disabled: "true"
  11.         }
  12. }

Then in the delegate:

  1. Item {
  2.         state: (typeof model.disabled != "undefined"  && model.disabled == "true" ? "disabled" : "")
  3.         anchors.centerIn: (typeof model.position == "undefined" || model.position == "left" : leftContainer ? rightContainer);
  4. }

 
  ‹‹ Qt Quick components available      Page component tutorial ››

You must log in to post a reply. Not a member yet? Register here!