小编Bea*_*ear的帖子

在 ListModel 中传递数组

我想知道如何在 ListModel 中传递数组?

好的,在 QML 中,我有一个 ListView,我将其设置ListModel如下:

model: ListModel
{
    id: myList   
    ListElement 
    {
        name: ""
        card: 0
        books: []
    }

}
Run Code Online (Sandbox Code Playgroud)

我可以使用以下方法附加到它:

myList.append({name:"terry", card:00100, books:["024589","865976","879582","215645"]}); 
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在屏幕上输出它时,我得到了这个。

{
    "card": 00100
    "books": {
        "objectName": "",
        "count": 4,
        "dynamicRoles": false
     },
    "name": "terry",
    "name": "terry"
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么我会得到 2 个名字!以及如何获得书籍的价值?

我仰望的QML文件的ListModelListElement找不到,所有的例子是整数或字符串与传递一个数组东西。

知道如何获得日期吗?
我确实通过在Delegate 中调用数组来解决它,Component.onCompleted:{}但我认为这不是一个好的/正确的方法,因为Delegate不负责保存数据并且应该在Model 中完成,如果我错了,请纠正我。

谢谢你的时间。

Edit01:感谢您的回复,这就是我需要数组的原因:我在Delegate 中有一个ComboBox,如下所示:

delegate: Rectangle
    {
     id: …
Run Code Online (Sandbox Code Playgroud)

javascript qml

2
推荐指数
1
解决办法
3762
查看次数

ImageIO - 从加载的图像中获取图像宽度和高度

我需要使用 imageio 获取图像的宽度和高度,使用 将图像加载到 imageio 中imread,如何获得图像的高度和宽度,或者换句话说就是图像的分辨率?在文档中,它提到它将返回 numpy 数组

例子:

>>> from imageio import imread
>>> image_date = imread('c:/myImage.png')
Run Code Online (Sandbox Code Playgroud)

当我打印出来时,我相信它会返回一个颜色数组列表

>>> print image_date
[[[ 18  23  16]
  [ 31  32  24]
  [ 34  29  23]
  ..., 
  [ 97  73  49]
  [ 95  73  50]
  [ 94  72  49]]

 [[ 23  24  18]
  [ 30  30  22]
  [ 36  29  21]
  ..., 
  [ 98  74  50]
  [ 95  73  50]
  [ 95  73  50]]

 [[ 32  27  21] …
Run Code Online (Sandbox Code Playgroud)

numpy python-2.7 python-imageio

2
推荐指数
1
解决办法
4290
查看次数

基于给定角度的"圆上点"

好吧,我有一个圆圈,我希望得到90度起源的圆点.

def point_on_circle():
    '''
        Finding the x,y coordinates on circle, based on given angle
    '''
    from math import cos, sin
    #center of circle, angle in degree and radius of circle
    center = [0,0]
    angle = 90
    radius = 100
    #x = offsetX + radius * Cosine(Degree)
    x = center[0] + (radius * cos(angle))
    #y = offsetY + radius * Sine(Degree)
    y = center[1] + (radius * sin(angle))

    return x,y

>>> print point_on_circle()
[-44.8073616129 , 89.3996663601]
Run Code Online (Sandbox Code Playgroud)

因为pi从3点开始,我预计会得到x=0,y=100但我不知道为什么我会这样做. …

python trigonometry python-2.7

0
推荐指数
1
解决办法
3237
查看次数

Java中的“在”和“不在”

我是 Java 新手,我想知道是否有办法根据另一个字符串检查一个字符串,我已经在 Python 中像这样完成了“

text = "Tree"
if "re" in text:
    print "yes, there is re exist in Tree"
Run Code Online (Sandbox Code Playgroud)

我们在java中有这样的方式来检查一个字符串是否存在于另一个字符串中吗?

编辑:我以 String 为例,我主要是在寻找像 python 那样的函数,正如我在 java 中的“in”和“not in”标题中提到的,来比较存在于另一个变量中的任何变量。

在 python 中,我可以比较数组列表与单个字符串变量:

myList = ["Apple", "Tree"]
if "Apple" in myList:
    print "yes, Apple exist"
Run Code Online (Sandbox Code Playgroud)

偶数数组vs数组

myList = ["Apple", "Tree","Seed"]
if ["Apple","Seed"] in myList:
    print "yes, there is Apple and Seed in your list"
Run Code Online (Sandbox Code Playgroud)

和单个整数vs数组 …

java python-2.7

0
推荐指数
1
解决办法
3883
查看次数