使用1-25配置QML组合框的简单方法 [英] Easy way to configure QML combobox with 1-25

查看:102
本文介绍了使用1-25配置QML组合框的简单方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个简单的下拉框,其中包含数字1到25(含1和25).

I have a need for a simple drop-down box containing the numbers 1 through 25 inclusive.

如果将模型设置为简单的25,则将得到024的值.我知道我可以有一个更复杂的列表模型,但是在应该能够即时计算它们的情况下构造大量的值数组似乎很愚蠢.

If I set the model up as a simple 25, I get the values 0 through 24 inclusive. I know I can have a more complicated list model but it seems rather silly to construct a massive array of values when they should be able to be calculated on the fly.

根据我的阅读,创建一个用于设置显示值的委托应该很简单,但是要使用QML:

From what I read, it should be a simple matter to create a delegate for setting the display values but, with the QML:

ComboBox {
    width: 100
    model: 25
    delegate: ItemDelegate {
        text: index + 1
    }
}

下拉选择区域中的

是正确的,但选择中显示的值仍从零开始.

the values in the drop-down selection area are correct but the value displayed on selection are still zero-based.

如何同时获得选择区域作为值1..25?

How do I get both the selection area and the value to be the values 1..25?

推荐答案

您可以为组合框设置displayText: currentIndex + 1:

ComboBox {
    width: 100
    model: 25
    delegate: ItemDelegate {
        text: index + 1
    }
    displayText: currentIndex + 1
}

这篇关于使用1-25配置QML组合框的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆