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. C++ QAbstractListModel delegate dependency issue

C++ QAbstractListModel delegate dependency issue

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 321 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Mcmatt90
    wrote on last edited by
    #1

    I have yet to find a solution for this question or maybe I'm not thinking about it correctly. So I have a QAbractListModel that has two sliders (settings). I have reimplemented setData, data etc. However, the one slider value is dependent on another. If the first slider is set to false it should automatically make the second slider false and also disable it (user can't interact).

    Where should this check be made, in setData()? I also have the issue of the slider value not getting actually written until the user clicks a save button. If the user navigates to another page, it should reset to the previous value. So, I guess it's technically a tempValue that is changing the slider? I'm just not sure if there is a built-in method for handling delegates that affect other delegates in a model. Any help or suggestions is greatly appreciated!

    jeremy_kJ 1 Reply Last reply
    0
    • M Mcmatt90

      I have yet to find a solution for this question or maybe I'm not thinking about it correctly. So I have a QAbractListModel that has two sliders (settings). I have reimplemented setData, data etc. However, the one slider value is dependent on another. If the first slider is set to false it should automatically make the second slider false and also disable it (user can't interact).

      Where should this check be made, in setData()? I also have the issue of the slider value not getting actually written until the user clicks a save button. If the user navigates to another page, it should reset to the previous value. So, I guess it's technically a tempValue that is changing the slider? I'm just not sure if there is a built-in method for handling delegates that affect other delegates in a model. Any help or suggestions is greatly appreciated!

      jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      Does the second slider need to be set to false AND disabled, or is disabled alone sufficient?

      I've typically represented this sort of relationship in the delegate, presuming that the view can be depended on for consistency.

      ListModel {
          model: theModel
          delegate: Row {
              Switch { id: s1; checked: model.s1 }
              Switch { id: s2; checked: model.s2; enabled: s1.checked }
              Button { text: "Commit"; onClicked: { model.s1 = s1.checked; model.s2 = s2.checked; } }
          }
      }
      

      For a solution like the above, be aware that the view can destroy delegate instances as they scroll off the screen. That can be prevented through various mechanisms such as disabling scrolling when modified, or storing the values in a temporary model.

      Asking a question about code? http://eel.is/iso-c++/testcase/

      M 1 Reply Last reply
      0
      • jeremy_kJ jeremy_k

        Does the second slider need to be set to false AND disabled, or is disabled alone sufficient?

        I've typically represented this sort of relationship in the delegate, presuming that the view can be depended on for consistency.

        ListModel {
            model: theModel
            delegate: Row {
                Switch { id: s1; checked: model.s1 }
                Switch { id: s2; checked: model.s2; enabled: s1.checked }
                Button { text: "Commit"; onClicked: { model.s1 = s1.checked; model.s2 = s2.checked; } }
            }
        }
        

        For a solution like the above, be aware that the view can destroy delegate instances as they scroll off the screen. That can be prevented through various mechanisms such as disabling scrolling when modified, or storing the values in a temporary model.

        M Offline
        M Offline
        Mcmatt90
        wrote on last edited by
        #3

        @jeremy_k needs to be set false AND disabled. I am actually storing these values in a qsettings file when save is pressed and use a c++ abstractListModel (there's several different setting pages with more complex setting objects, this one just has two sliders).

        GrecKoG 1 Reply Last reply
        0
        • M Mcmatt90

          @jeremy_k needs to be set false AND disabled. I am actually storing these values in a qsettings file when save is pressed and use a c++ abstractListModel (there's several different setting pages with more complex setting objects, this one just has two sliders).

          GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          @Mcmatt90 What is your model and view like?
          Each slider represents a row? Your roles are name,type,value?

          Can you show some of your QML code?

          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