• 5477阅读
  • 5回复

[讨论]我哪里写错了吗? [复制链接]

上一主题 下一主题
离线shizhanbiao
 
只看楼主 倒序阅读 楼主  发表于: 2013-08-26
import QtQuick 1.1
Rectangle {     id:page     width:500;height:200     color:"lightgray"
     Text{     id:helloText     text:"hello world"     y:30     anchors.horizontalCenter: page.horizontalCenter     font.pointSize: 24;font.bold: true     }     Grid{      id:colorPicker      x:4;anchors.bottom: page.bottom;anchors.bottomMargin: 4      rows:2;columns: 3;spacing: 3
      Cell { cellColor: "red"; onClicked: helloText.color = cellColor }      Cell { cellColor: "green"; onClicked: helloText.color = cellColor }      Cell { cellColor: "blue"; onClicked: helloText.color = cellColor }      Cell { cellColor: "yellow"; onClicked: helloText.color = cellColor }      Cell { cellColor: "steelblue"; onClicked: helloText.color = cellColor }      Cell { cellColor: "black"; onClicked: helloText.color = cellColor }     }}
第二个。


import QtQuick 1.1
Item{ id:container property alias cellColor: rectangle.color signal clicked(color cellColor) width:40;height:25 Rectangle {  id:rectange  border.color: "red"  anchors.fill: parent }
MouseArea {  anchors.fill:parent  onClicked: container.clicked(container.cellColor) }}怎么写完了什么结果也没有呢。求解释呀。





本人刚学习这个,不太懂,他说的cell组件是个什么。怎么我写的东西跟他的一样,为什么出不来效果呢。
离线tompsontan

只看该作者 1楼 发表于: 2013-08-26
你这个Cell是什么东东?全部代码都贴出来了吗?是不是少了Cell.qml
看淡得失
离线tompsontan

只看该作者 2楼 发表于: 2013-08-26
回 楼主(shizhanbiao) 的帖子


你是按这个来做的吧?

看淡得失
离线realfan

只看该作者 3楼 发表于: 2013-08-27
Cell就是Cell.qml文件,定义了矩形块
离线realfan

只看该作者 4楼 发表于: 2013-08-27
Cell.qml
import QtQuick 1.1 //( 可以改成import QtQuick 2.0,根据你的环境)
Item {
    id: container  
    property alias cellColor: rectangle.color  
    signal clicked(color cellColor)  
    width: 40; height: 25  
    Rectangle {  
        id: rectangle  
        border.color: "white"  
        anchors.fill: parent  
    }  
    MouseArea {  
        anchors.fill: parent  
        onClicked: container.clicked(container.cellColor)  
    }  
}
离线wuming123057

只看该作者 5楼 发表于: 2013-08-27

Cell.qml文件中
Rectangle {
id:rectange

少加一个字母l,应该为rectangle,其他的问题没有
快速回复
限100 字节
 
上一个 下一个