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. function binding property
Forum Updated to NodeBB v4.3 + New Features

function binding property

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 2 Posters 744 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.
  • G Offline
    G Offline
    Galilio
    wrote on last edited by
    #1

    hello together
    following I have:

    function buttonIsSelected(index)
    {
    	if(index >= 0){
    		listViewId.currentIndex = index
    		console.log("listViewId Index --------------------------------------------------",index)
    		return true
    	}else
    		return false
    }
    
    ListView
    {
    	id: listViewId
    	anchors.top = parent.top
    	.....
    	model: 4
    	delegate: Button {
    		id: tabButtonId
    		width: 150
    		height: 150
    		selected: buttonIsSelected(index)   // Problem is hier
    		.....
    	}
    
    }
    
    

    Why does the function buttonIsSelected (index) always return false?
    What am I doing wrong?

    thanks

    J.HilkJ 1 Reply Last reply
    0
    • G Galilio

      hello together
      following I have:

      function buttonIsSelected(index)
      {
      	if(index >= 0){
      		listViewId.currentIndex = index
      		console.log("listViewId Index --------------------------------------------------",index)
      		return true
      	}else
      		return false
      }
      
      ListView
      {
      	id: listViewId
      	anchors.top = parent.top
      	.....
      	model: 4
      	delegate: Button {
      		id: tabButtonId
      		width: 150
      		height: 150
      		selected: buttonIsSelected(index)   // Problem is hier
      		.....
      	}
      
      }
      
      

      Why does the function buttonIsSelected (index) always return false?
      What am I doing wrong?

      thanks

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @Galilio no idea, works absolutely fine for me

      Window {
          visible: true
          width: 400
          height: 750
          title: qsTr("Hello World")
      
          function buttonIsSelected(index)
          {
              if(index >= 0){
                  listViewId.currentIndex = index
                  console.log("listViewId Index --------------------------------------------------",index)
                  return true
              }else
                  return false
          }
      
          ListView
          {
              id: listViewId
              anchors.fill: parent
              model: 4
              delegate: Button {
                  id: tabButtonId
                  width: 150
                  height: 150
                  property bool selected: buttonIsSelected(index)   // Problem is hier
                  onSelectedChanged: console.log("selected changed to", selected)
              }
          }
      }
      
      //Output
      qml: listViewId Index -------------------------------------------------- 0
      qml: selected changed to true
      qml: listViewId Index -------------------------------------------------- 1
      qml: selected changed to true
      qml: listViewId Index -------------------------------------------------- 2
      qml: selected changed to true
      qml: listViewId Index -------------------------------------------------- 3
      qml: selected changed to true
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Galilio
        wrote on last edited by
        #3

        What is wrong if I do so in ListView?

        property bool selected: listViewId.currentIndex === index
        
        G 1 Reply Last reply
        0
        • G Galilio

          What is wrong if I do so in ListView?

          property bool selected: listViewId.currentIndex === index
          
          G Offline
          G Offline
          Galilio
          wrote on last edited by
          #4

          @Galilio

          The problem with this notation (property bool selected: listViewId.currentIndex === index) is that index and currentIndex do not always have the same value

          J.HilkJ 1 Reply Last reply
          0
          • G Galilio

            @Galilio

            The problem with this notation (property bool selected: listViewId.currentIndex === index) is that index and currentIndex do not always have the same value

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @Galilio
            I'm not sure I understand your problem, this

            ListView
                {
                    id: listViewId
                    anchors.fill: parent
                    model: 4
                    delegate: Button {
                        id: tabButtonId
                        width: 150
                        height: 150
                        property bool selected:listViewId.currentIndex === index/* buttonIsSelected(index)*/   // Problem is hier
                        onSelectedChanged: console.log("selected changed to", selected, "of index:", index)
                        text: index
                        background: Rectangle{
                            color: tabButtonId.selected ? "green" : "red"
                        }
                        onClicked:{
                            listViewId.currentIndex = index
                        }
                    }
                }
            

            works just fine!


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Galilio
              wrote on last edited by
              #6

              Die Farbe der selectiereten Button bleibt aber gleich und das ist nicht das Ziel.
              Ziel wäre: sobald ich einen button selktiere muss der andere Button nicht mehr die selktiere frabe haben
              sprich:
              Button 1 ist selktiert (color "green")
              Button 2 ist selktiert (color "green") und Button 1 wird "red" gefährbt
              ...

              J.HilkJ 1 Reply Last reply
              0
              • G Galilio

                Die Farbe der selectiereten Button bleibt aber gleich und das ist nicht das Ziel.
                Ziel wäre: sobald ich einen button selktiere muss der andere Button nicht mehr die selktiere frabe haben
                sprich:
                Button 1 ist selktiert (color "green")
                Button 2 ist selktiert (color "green") und Button 1 wird "red" gefährbt
                ...

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #7

                @Galilio
                genau
                https://vimeo.com/371847377


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  Galilio
                  wrote on last edited by
                  #8

                  Link leider geht nicht

                  J.HilkJ 1 Reply Last reply
                  0
                  • G Galilio

                    Link leider geht nicht

                    J.HilkJ Offline
                    J.HilkJ Offline
                    J.Hilk
                    Moderators
                    wrote on last edited by
                    #9

                    @Galilio
                    fixed the link, should now work


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    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