Tableview row should change on pressed in QML
-
@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. -
@Bhushan_Sure, very nice.
Also, please share your code sample here so that others can benefit from it. -
@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
} -
@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 ? -
@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 } } }
-
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:Cok 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"; }
-
@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)) }
- 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)
-
This post is deleted!
-
@Bhushan_Sure sry i was reading this as single line expression like ...
my badvar 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))
-
@LeLev Thankyou for your inputs :) :)