QML TabView中Tab控件无法访问子控件id的解决办法

import QtQuick 2.12

import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQml 2.0
TabView {
    property string font_color: "#EFEFEF";
    onCurrentIndexChanged:
    {
        if(currentIndex==0)
        {
            //console.log("onLoaded ipaddress = ",ipaddress);
            last_tab.reset_ip();
            //这里是切换tab页的时候,根据当前切换的下标进行调用,可以根据Tab的index进行动态绘制其中的内容
        }
    }
    Tab {
        property Item  ip_label:null
        property Item  ip_text:null
        id: last_tab
        anchors.topMargin:40
        anchors.bottomMargin:160
        anchors.leftMargin: 100

        function reset_ip(){
            if(ip_label != null){
                if(ip_text.visible){
                    var ipaddress = config.ipv4_address().trim();
                    ip_text.text = ipaddress;
                }
            }
        }
        onLoaded:{
            ip_label = item.ip_label
            ip_text = item.ip_text
            //关键在这里,动态链接到实例化后的item中的属性。
            //item是Tab中的一个成员变量,是实例化后的具体子控件的对象
        }
        GridLayout {
            property Item  ip_label:ip_address_label
            property Item  ip_text:ip_address_text
            id:grid_layout
            anchors.fill: parent
            columns: 2
            flow: GridLayout.LeftToRight
            Label 
            {
                id:ip_address_label;
                text: "IP 地址";
                color: font_color;
                font.pixelSize: 18;
                visible:config.ipv4_address().trim() != "";

            }
            Text {
                id:ip_address_text
                text: config.ipv4_address().trim()
                font.pixelSize: 18
                color: font_color
                visible:config.ipv4_address().trim() != ""
            }
  
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zanglengyu

敲碗要饭

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值