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. Tableview row should change on pressed in QML
Qt 6.11 is out! See what's new in the release blog

Tableview row should change on pressed in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
13 Posts 3 Posters 2.3k 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.
  • Nikhilesh NN Nikhilesh N

    @Bhushan_Sure, see this part of your code.

                    MouseArea
                    {
                        id:table_mouse_id
                        anchors.fill: parent
    
                        onPressed:
                        {
                           source = image 4
                        }
    
                        onReleased:
                        {
                            tableView.currentRow = styleData.row
                        }
                    }
    

    onPressed image 4 is getting load but Onreleased it is remaining as it is, everything is not being updated.

    I suspect the above problem is hapenning during the 'onPressed' handler, and image4 is being updated in styleData.row also because of it.
    What is actually stored in styleData.row? Can you add some console debug statements in either of the MouseArea handlers if printable console logs are possible?

    Bhushan_SureB Offline
    Bhushan_SureB Offline
    Bhushan_Sure
    wrote on last edited by
    #4

    @Nikhilesh-N Thank you for suggestion. Hi nikhilesh, i resolved the issue with some different way , what i did is i put two images and
    "onpressed" i am making one image.visible = true and "onreleased ", i am making image.visible = false.

    1 Reply Last reply
    1
    • Nikhilesh NN Offline
      Nikhilesh NN Offline
      Nikhilesh N
      wrote on last edited by
      #5

      @Bhushan_Sure, very nice.
      Also, please share your code sample here so that others can benefit from it.

      Bhushan_SureB 1 Reply Last reply
      0
      • Bhushan_SureB Bhushan_Sure

        @Bhushan_Sure @J-Hilk @LeLev @dheerendra @Nikhilesh-N Any suggestion ?

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by ODБOï
        #6

        @Bhushan_Sure hi, you can't do this :

        Image {
              id:item_id
              height: (tableView.height/(listmodel.count < 4 ? listmodel.count : 4))
              source:
                        {
                            var activeRow = tableView.currentRow === styleData.row
                            (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                        }
        

        you assign a function to source of your image, but that function does not return anything, you had to return var activeRow

        eg :

        Rectangle {
            property bool _isRed: false
            color: {var c = _isRed ? "red" : "blue";return c} 
        }
        

        @Bhushan_Sure said in Tableview row should change on pressed in QML:

        "onpressed" i am making one image.visible = true and "onreleased ", i am making image.visible = false.

        you can do

        Image{
        visible : mouseAreaId.pressed
        }

        Bhushan_SureB 1 Reply Last reply
        2
        • ODБOïO ODБOï

          @Bhushan_Sure hi, you can't do this :

          Image {
                id:item_id
                height: (tableView.height/(listmodel.count < 4 ? listmodel.count : 4))
                source:
                          {
                              var activeRow = tableView.currentRow === styleData.row
                              (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                          }
          

          you assign a function to source of your image, but that function does not return anything, you had to return var activeRow

          eg :

          Rectangle {
              property bool _isRed: false
              color: {var c = _isRed ? "red" : "blue";return c} 
          }
          

          @Bhushan_Sure said in Tableview row should change on pressed in QML:

          "onpressed" i am making one image.visible = true and "onreleased ", i am making image.visible = false.

          you can do

          Image{
          visible : mouseAreaId.pressed
          }

          Bhushan_SureB Offline
          Bhushan_SureB Offline
          Bhushan_Sure
          wrote on last edited by
          #7

          @LeLev Hi, i am not returning anything but it is taking values, suppose
          A?B:C, so suppose A is true the it is returning B automatically, is it not right way ?

          ODБOïO 1 Reply Last reply
          0
          • Nikhilesh NN Nikhilesh N

            @Bhushan_Sure, very nice.
            Also, please share your code sample here so that others can benefit from it.

            Bhushan_SureB Offline
            Bhushan_SureB Offline
            Bhushan_Sure
            wrote on last edited by
            #8

            @Nikhilesh-N Yes, Source code is attached.

            itemDelegate: Image
                        {
                            id:item_id
                            height: (tableView.height/(listmodel.count < 4 ? listmodel.count : 4))
                            source:
                            {
                                var activeRow = tableView.currentRow === styleData.row
                                (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                            }
            
                            MouseArea
                            {
                                id:table_mouse_id
                                anchors.fill: parent
            
                                onPressed:
                                {
                                  image4.visible=true
                                }
            
                                onReleased:
                                {
                                    image4.visible=false
                                }
                            }
            }
            
            1 Reply Last reply
            1
            • Bhushan_SureB Bhushan_Sure

              @LeLev Hi, i am not returning anything but it is taking values, suppose
              A?B:C, so suppose A is true the it is returning B automatically, is it not right way ?

              ODБOïO Offline
              ODБOïO Offline
              ODБOï
              wrote on last edited by ODБOï
              #9

              hi,

              @Bhushan_Sure said in Tableview row should change on pressed in QML:

              i am not returning anything but it is taking values

              no, you are just assigning your image path to a variable called var activeRow

              @Bhushan_Sure said in Tableview row should change on pressed in QML:

              suppose
              A?B:C

              ok but you do var D = A?B:C

              please test it and you will see

              Rectangle {
                  property bool _isRed: false
                  color: {var c = _isRed ? "red" : "blue";}  // you return nothing, **var c** is "blue" but the rectangle no!
              }
              
              Rectangle {
                  property bool _isRed: false
                  color: {var c = _isRed ? "red" : "blue";return c }  // now color will be blue
              // or return isRed ? "red" : "blue";
              // or isRed ? "red" : "blue";
              }
              
              Bhushan_SureB 1 Reply Last reply
              0
              • ODБOïO ODБOï

                hi,

                @Bhushan_Sure said in Tableview row should change on pressed in QML:

                i am not returning anything but it is taking values

                no, you are just assigning your image path to a variable called var activeRow

                @Bhushan_Sure said in Tableview row should change on pressed in QML:

                suppose
                A?B:C

                ok but you do var D = A?B:C

                please test it and you will see

                Rectangle {
                    property bool _isRed: false
                    color: {var c = _isRed ? "red" : "blue";}  // you return nothing, **var c** is "blue" but the rectangle no!
                }
                
                Rectangle {
                    property bool _isRed: false
                    color: {var c = _isRed ? "red" : "blue";return c }  // now color will be blue
                // or return isRed ? "red" : "blue";
                // or isRed ? "red" : "blue";
                }
                
                Bhushan_SureB Offline
                Bhushan_SureB Offline
                Bhushan_Sure
                wrote on last edited by Bhushan_Sure
                #10

                @LeLev I think you are talking about following

                source:
                                {
                                    var activeRow = tableView.currentRow === styleData.row
                                    (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                                }
                
                1. var activeRow = tableView.currentRow === styleData.row

                This line (tableView.currentRow === styleData.row) will return boolean
                value and that boolean value will get saved in var activerow.
                2)
                then this line
                activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3)

                will check if **activerow** is true then **image1** or else part.
                **activerow** will get updated in 1)
                
                ODБOïO 2 Replies Last reply
                1
                • Bhushan_SureB Bhushan_Sure

                  @LeLev I think you are talking about following

                  source:
                                  {
                                      var activeRow = tableView.currentRow === styleData.row
                                      (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                                  }
                  
                  1. var activeRow = tableView.currentRow === styleData.row

                  This line (tableView.currentRow === styleData.row) will return boolean
                  value and that boolean value will get saved in var activerow.
                  2)
                  then this line
                  activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3)

                  will check if **activerow** is true then **image1** or else part.
                  **activerow** will get updated in 1)
                  
                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by ODБOï
                  #11
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • Bhushan_SureB Bhushan_Sure

                    @LeLev I think you are talking about following

                    source:
                                    {
                                        var activeRow = tableView.currentRow === styleData.row
                                        (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                                    }
                    
                    1. var activeRow = tableView.currentRow === styleData.row

                    This line (tableView.currentRow === styleData.row) will return boolean
                    value and that boolean value will get saved in var activerow.
                    2)
                    then this line
                    activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3)

                    will check if **activerow** is true then **image1** or else part.
                    **activerow** will get updated in 1)
                    
                    ODБOïO Offline
                    ODБOïO Offline
                    ODБOï
                    wrote on last edited by ODБOï
                    #12

                    @Bhushan_Sure sry i was reading this as single line expression like ...
                    my bad

                    var activeRow = tableView.currentRow === styleData.row (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                    

                    this line is actually returning

                    (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                    
                    Bhushan_SureB 1 Reply Last reply
                    1
                    • ODБOïO ODБOï

                      @Bhushan_Sure sry i was reading this as single line expression like ...
                      my bad

                      var activeRow = tableView.currentRow === styleData.row (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                      

                      this line is actually returning

                      (activeRow ? Image 1 : styleData.row % 2 ? (image 2): (image 3))
                      
                      Bhushan_SureB Offline
                      Bhushan_SureB Offline
                      Bhushan_Sure
                      wrote on last edited by
                      #13

                      @LeLev Thankyou for your inputs :) :)

                      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