Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListView, ListModel and ListElement and trying very hard not to hard code, which would make it worthless

ListView, ListModel and ListElement and trying very hard not to hard code, which would make it worthless

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 464 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VFCraig
    wrote on last edited by
    #1

    No, I am not going to post code. If you don't understand what I am asking, don't respond.

    I have a ListView/Model/Element designed to create a menu of buttons. These buttons, for the most part, launch setup dialogs. These buttons also have fields that show the current value of that set by the associated dialogs.

    Seems even though the Component defined for the ListElement is a custom button that handles all these settings (yes, the button works it is used throughout the program), I cannot simply set the fields within the ListElement to be transferred to a new instance of the button. I have to define new variables that are then used to set the button values.

    Question 1) When using setProperty to modify the current value displayed on the button, do I use the name of the variable used to initialize the Component or do I use the actual name of the variable defined in the button. (variable = property, for those confused)?

    Question 2) One dialog launched from the menu allows the user to choose the preferred units used for a patient (yep, medical device) size. Depending on the choice made, another menu button is set accordingly so it brings up the appropriate dialog for the chosen units. To do this I have to insert a new menu button at the location of the current and then delete the current with an index of its original plus one. But the menu/ListView only updates after setting the units TWICE. It fails to redraw and show the new button even though a specific call is made to, forceLayout(). How do I get the ListView to show the changes made using the functions provided by the class, insert, remove, setProperty?

    B 1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      1 - the ListModel is not aware of your component, so setProperty applies to a preexisting role of your ListElements. You need to map your model roles to your Button properties in your delegate.

      2 - It should just work if you are doing this correctly.

      1 Reply Last reply
      0
      • V VFCraig

        No, I am not going to post code. If you don't understand what I am asking, don't respond.

        I have a ListView/Model/Element designed to create a menu of buttons. These buttons, for the most part, launch setup dialogs. These buttons also have fields that show the current value of that set by the associated dialogs.

        Seems even though the Component defined for the ListElement is a custom button that handles all these settings (yes, the button works it is used throughout the program), I cannot simply set the fields within the ListElement to be transferred to a new instance of the button. I have to define new variables that are then used to set the button values.

        Question 1) When using setProperty to modify the current value displayed on the button, do I use the name of the variable used to initialize the Component or do I use the actual name of the variable defined in the button. (variable = property, for those confused)?

        Question 2) One dialog launched from the menu allows the user to choose the preferred units used for a patient (yep, medical device) size. Depending on the choice made, another menu button is set accordingly so it brings up the appropriate dialog for the chosen units. To do this I have to insert a new menu button at the location of the current and then delete the current with an index of its original plus one. But the menu/ListView only updates after setting the units TWICE. It fails to redraw and show the new button even though a specific call is made to, forceLayout(). How do I get the ListView to show the changes made using the functions provided by the class, insert, remove, setProperty?

        B Offline
        B Offline
        Bob64
        wrote on last edited by
        #3

        @VFCraig I'm struggling to understand exactly what you are doing. It almost sounds like you are trying to store your button components in your ListModel. What's all this business about "new variables"?

        V 1 Reply Last reply
        0
        • B Bob64

          @VFCraig I'm struggling to understand exactly what you are doing. It almost sounds like you are trying to store your button components in your ListModel. What's all this business about "new variables"?

          V Offline
          V Offline
          VFCraig
          wrote on last edited by
          #4

          @Bob64 The button has a source string property (optional icon path string), btnLabel string property, and a currentValue string property. But when I define my ListElements, which are these buttons, initialized in delegate component and I have to provide alternate names such as, theSource, theBtnLabel, theCurrentValue and assign the button members to these "variable", these alternate names.

          Wouldn't it seem to make more sense that since the ListElement is providing data to initialize the button, it would be able to simply set source, btnLabel, currentValue in the ListElement and the delegate would create the button using those values? That way the delegate would just create the button, maybe assign a height and set width to that of the ListView (which it does) and be done.

          B 1 Reply Last reply
          0
          • V VFCraig

            @Bob64 The button has a source string property (optional icon path string), btnLabel string property, and a currentValue string property. But when I define my ListElements, which are these buttons, initialized in delegate component and I have to provide alternate names such as, theSource, theBtnLabel, theCurrentValue and assign the button members to these "variable", these alternate names.

            Wouldn't it seem to make more sense that since the ListElement is providing data to initialize the button, it would be able to simply set source, btnLabel, currentValue in the ListElement and the delegate would create the button using those values? That way the delegate would just create the button, maybe assign a height and set width to that of the ListView (which it does) and be done.

            B Offline
            B Offline
            Bob64
            wrote on last edited by
            #5

            @VFCraig Ok, I see what you are saying, but you have a very specific use case there, where your delegates simply create a button. It's not unusual in ListView instances to define more complex delegates with two or more items in some sort of layout. In such cases, there isn't such a simple initialisation as each delegate item will pick out whatever model data it needs. Additionally, it is not unusual not to bind the data directly to delegate properties but instead to bind to expressions involving the model data.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved