全面菜鸟 2017-12-30 07:57 采纳率: 83.3%
浏览 1877
已采纳

qml使用中在listview样式中加入一个button后button的点击效果没有了

小弟最近用qtquick做pc应用,在用listview的时候,在listview的样式中加入了一个button但是没有了button的点击效果,只有样式的的鼠标点击效果,还望大神给解
决下; 类似代码如下:
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 2.1

Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
property var boxarray: [];

MouseArea {
anchors.fill: parent

}
Rectangle{
anchors.fill: parent;

Button{
    anchors.horizontalCenter: parent.horizontalCenter;
    anchors.top: parent.top;
    width: 50;
    height: 40;
    onClicked: {
       frid.model.append({"name": "118"})
    }

}


Component{
    id: commmm;
    Rectangle{
        id: rrttc
        width: frid.cellWidth;
        height: frid.cellHeight;

        color: GridView.isCurrentItem ? "red" : "blue"

        Text {

            text: name;
            color: rrttc.GridView.isCurrentItem ? "blue" : "red"
        }

        Button{
            anchors.bottom: parent.bottom;
            anchors.right: parent.right;
            width: 30;
            height: 30;
            onClicked: {
                console.log("2222")
            }

        }

        MouseArea{
            anchors.fill: parent;
            onClicked: {
                frid.currentIndex = index;
                console.log("1111")
            }
        }
    }
}


GridView{
    id: frid
    anchors.top: parent.top;
    anchors.topMargin: 40;
    anchors.left: parent.left;
    anchors.right: parent.right;
    anchors.bottom: parent.bottom;
    model: contactModel;
    focus: true;
    highlight: Rectangle{color: "lightsteelblue"; radius: 4}
    delegate: commmm
}

ListModel{
    id: contactModel
    ListElement{
        name: "111";
    }

    ListElement{
        name: "112";
    }

    ListElement{
        name: "113";
    }

    ListElement{
        name: "114";
    }

    ListElement{
        name: "115";
    }
}

}
}

这是一个类似的代码,就是运行起来的话button的点击效果没有也就是只打印“1111”不会打印“2222”,也就是button根本不能被点击,看一些其他的貌似是冲突了,有没有什么解决方法呢

  • 写回答

1条回答 默认 最新

  • devmiao 2017-12-30 15:25
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?