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. Changing enabled properties depending of user rights
Forum Updated to NodeBB v4.3 + New Features

Changing enabled properties depending of user rights

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 431 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.
  • the moebiusT Offline
    the moebiusT Offline
    the moebius
    wrote on last edited by the moebius
    #1

    Hello

    I'm trying to disable options for users in a list depending of their rights. Here is the idea :

    main.qml

    [ListModel {
            id: modelActivityDataId
            ListElement {
                title: qsTr("Login")
                image: "qrc:/res/site_load.png"
                page: "Login.qml"
            }
            ListElement {
                title: qsTr("Edition de Site")
                image: "qrc:/res/configuration.png"
                page: "SiteForm.qml"
            }
            ListElement {
                title: qsTr("Paramètres")
                image: "qrc:/res/applications-system.png"
                page: "ConfigurationForm.qml"
            }
    }
    StackView {
            id: stackView
            anchors.fill: parent
            focus: true
            Keys.onReleased: if (event.key === Qt.Key_Back && stackView.depth > 1) {
                                 stackView.pop();
                                 event.accepted = true;
                             }
    
            initialItem: Item {
                width: parent.width
                height: parent.height
                ListView {
                    model: modelActivityDataId
                    anchors.fill: parent
                    delegate: ThemeDelegate {
                        id: modelActivityDelegateId
                        text: title
                        imagefile : image
                        onClicked: stackView.pushItem(Qt.resolvedUrl(page))
                        states:
                        [
                            State
                            {
                                name : "defaultState"
                                PropertyChanges
                                {
                                    target: modelActivityDataId
                                    enabled: index === 0
                                }
                            },
                            State
                            {
                                name : "userLogged"
                                PropertyChanges
                                {
                                    target: modelActivityDataId
                                    enabled: index === 0 || index === 1
                                }
                            },
                            State
                            {
                                name : "adminLogged"
                                PropertyChanges
                                {
                                    target: modelActivityDataId
                                    enabled: index === 0 || index === 1 || index === 2
                                }
                            }
                        ]
                    }
                    Connections
                    {
                        target: userRights
                        onSglIsOut: modelActivityDelegateId.state = "defaultState"
                    }
                    Connections
                    {
                        target: userRights
                        onSglIsUser: modelActivityDelegateId.state = "userLogged"
                    }
                    Connections
                    {
                        target: userRights
                        onSglIsAdmin: modelActivityDelegateId.state = "adminLogged"
                    }
                }
            }
    ]
    

    the signals are sent from a Cpp classe userRightManager
    However, the states aren't recognised by the delegate...can't find a way to get them right...

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi @the-moebius,
      AFAIK delegates can't be accessed directly from outside . You will need to iterate the ListView children and change the state.
      But the best way would be to do it through model.

      157

      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