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 Update on Monday, May 27th 2025

function binding property

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 2 Posters 737 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 8 Nov 2019, 07:14 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 1 Reply Last reply 8 Nov 2019, 07:29
    0
    • G Galilio
      8 Nov 2019, 07:14

      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 Online
      J Online
      J.Hilk
      Moderators
      wrote on 8 Nov 2019, 07:29 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 8 Nov 2019, 10:14 last edited by
        #3

        What is wrong if I do so in ListView?

        property bool selected: listViewId.currentIndex === index
        
        G 1 Reply Last reply 8 Nov 2019, 10:21
        0
        • G Galilio
          8 Nov 2019, 10:14

          What is wrong if I do so in ListView?

          property bool selected: listViewId.currentIndex === index
          
          G Offline
          G Offline
          Galilio
          wrote on 8 Nov 2019, 10:21 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 1 Reply Last reply 8 Nov 2019, 10:23
          0
          • G Galilio
            8 Nov 2019, 10:21

            @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 Online
            J Online
            J.Hilk
            Moderators
            wrote on 8 Nov 2019, 10:23 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 8 Nov 2019, 10:46 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 1 Reply Last reply 8 Nov 2019, 10:58
              0
              • G Galilio
                8 Nov 2019, 10:46

                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 Online
                J Online
                J.Hilk
                Moderators
                wrote on 8 Nov 2019, 10:58 last edited by J.Hilk 11 Aug 2019, 11:49
                #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 8 Nov 2019, 11:43 last edited by
                  #8

                  Link leider geht nicht

                  J 1 Reply Last reply 8 Nov 2019, 11:50
                  0
                  • G Galilio
                    8 Nov 2019, 11:43

                    Link leider geht nicht

                    J Online
                    J Online
                    J.Hilk
                    Moderators
                    wrote on 8 Nov 2019, 11:50 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

                    1/9

                    8 Nov 2019, 07:14

                    • Login

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