门户
书籍
教程
论坛
问答
下载
签到
个人空间
帐号
自动登录
找回密码
密码
登录
立即注册
账号
自动登录
找回密码
密码
登录
立即注册
请绘制轨迹完成人机验证
由vaptcha提供技术支持
登录
注册
搜索
搜索
搜索
热搜
qml
quick
串口
输入中文
数据库
arm
百度地图
qt聊天
QT安装
安装
多窗口
中文乱码
聊天
局域网
鼠标
QT
图片
乱码
rs485通讯
多线程
android
多文档编辑器
本版
用户
本版
用户
【HUX】问题互助平台
博客
动态
好友
帖子
收藏
道具
勋章
任务
淘帖
动态
日志
相册
分享
记录
留言板
群组
门户
导读
排行榜
设置
我的收藏
退出
Qt开源社区
›
精华区(请在“有问必答”发帖)
›
有问必答
›
QML和QtQuick
›
qml:如何修改多个被点击的Rectangle里边Text的值? ...
发布主题
返回列表
qml:如何修改多个被点击的Rectangle里边Text的值?
2
回复
8816
查看
[复制链接]
469514939
当前离线
积分
6
469514939
累计签到:4 天
连续签到:1 天
来源:
2018-4-2 18:01:05
显示全部楼层
|
阅读模式
1
Qter豆
本帖最后由 469514939 于 2018-4-2 18:12 编辑
<div class="blockcode"><blockquote>import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
id: root
function changePlace(){
var list = placeGrid.children.children;
console.log(list);
console.log("count: " + list.length);
for ( var i in list) {
console.log("list[ " +i + " ] width = " + list[i].width)
console.log("list[ " +i + " ] height = " + list[i].height)
console.log("list[ " +i + " ] QQuick = " + list[i])
}
}
GridView {
clip: true
id:placeGrid
width: parent.width
height: parent.height
cellWidth: 80
cellHeight: 80
model: spaceModel
delegate: msnDelegate
focus: true
Component {
id: msnDelegate
Item{
width: placeGrid.cellWidth
height: placeGrid.cellHeight
Rectangle {
width:parent.width-2
height: parent.height-2
color: "gray"
radius: 5
id:place
anchors.centerIn: parent
Text {
id:placeNum
text: num
color: "white"
font.pixelSize: Math.floor(parent.width/2)
anchors.centerIn: parent
}
MouseArea{
anchors.fill: parent
onClicked: {place.state == "clicked" ? place.state = "" : place.state = "clicked";
console.log(parent.state);
}
}
states: [
State{
name: "clicked"
PropertyChanges { target: place; color: "#94a5d4"}
}
]
}
}
}
//list模型
ListModel {
id: spaceModel
ListElement { code:"A1"; num: 1; stock : 8; rows : "A"; columns:1;}
ListElement { code:"A2"; num: 2; stock : 8; rows : "A"; columns:2;}
ListElement { code:"A3"; num: 0; stock : 8; rows : "A"; columns:3;}
}
}
Button{
text: "change"
onClicked:changePlace();
y:100
}
}
复制代码
代码如上,我想修改被选中的矩形里边得数字。先选中矩形,然后点击按钮就统一修改被选中按钮里边数字。
附件:
您需要
登录
才可以下载或查看,没有帐号?
立即注册
最佳答案
Since
查看完整内容
建议你保存 点击了的按钮的 index 到 list ,然后 循环 ListModel , indexOf(index) ,如果返回 大于等于0 ,那就改变数字,你把 click 属性修改了,又不做判断,你要干啥?
回复
使用道具
举报
Since
当前离线
积分
837
Since
累计签到:742 天
连续签到:1 天
2018-4-2 18:01:06
显示全部楼层
建议你保存 点击了的按钮的 index 到 list ,然后 循环 ListModel , indexOf(index) ,如果返回 大于等于0 ,那就改变数字,你把 click 属性修改了,又不做判断,你要干啥?
评分
参与人数
1
人气
+1
收起
理由
469514939
+ 1
对我帮助很大!
查看全部评分
总评分 : 
人气
+1
回复
使用道具
举报
469514939
当前离线
积分
6
469514939
累计签到:4 天
连续签到:1 天
2018-4-2 19:11:48
显示全部楼层
噢噢,谢谢
。试了下保存到list然后循环model这方法可以。
我本来得打算是修改states属性后,通过children然后遍历已改变了state的矩形,再改变数字,但是children不到对象
回复
使用道具
举报
返回列表
发表新帖
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
立即注册
公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满)
我知道了