Помогите, пожалуйста, есть клеточное поле, как подсвечивать соседей при наведении наведении мышки на элемент? Qt QML
Сделала пока только подсветку самого элемента, а вот с соседями потерялась
property int pX
property int pY
MouseArea{
hoverEnabled: true
anchors.fill: parent
onEntered: {
//Запоминаем позиции
pX = brick.x
pY = brick.y
brick.color = "#baa804"
}
onExited: brick.color = "#fcec5b"
Ответы (1 шт):
Автор решения: eri
→ Ссылка
import QtQuick 2.0
Item {
width: 640
height: 640
Grid {
columns: 8
anchors.fill: parent
Repeater {
id : field
model: 64
Rectangle {
width: 80
height: 80
property var neibours : [index - 8, index + 8]
.concat(index % 8 == 0 ? []: [index - 1, index + 7, index - 9])
.concat((index - 7) % 8 == 0 ? [] : [index + 1, index - 7, index + 9])
.filter((neibour) => (neibour >= 0 && neibour < 64))
border.color: 'blue'
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
color = 'red'
neibours.forEach( (neibour) => field.itemAt(neibour).color = 'yellow')
}
onExited: {
color = 'white'
neibours.forEach( (neibour) => field.itemAt(neibour).color = 'white' )
}
}
}
}
}
}
Нужно посчитать каджому элементу соседей и дергать их по индексу из Repeater-а. Соседей можно считать заранее как у меня или внутри функций.