如何从Qt Designer / .ui文件向QComboBox添加项目数据 [英] How can I add item data to QComboBox from Qt Designer/.ui file

查看:428
本文介绍了如何从Qt Designer / .ui文件向QComboBox添加项目数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Qt Designer(嗯,实际上是Qt Creator,但是具体来说是从Qt Designer派生的部分),并且我已经在对话框中添加了一些QComboBox项,其中有恒定的项列表。我需要将组合框中的项目映射到字符串(与显示的字符串不同)。我想到的最好的主意是使用QComboBox :: itemData函数从所选项目中获取所需的字符串,但是我很难将关联的字符串添加到项目中。我到处都是设计师,还没有找到添加用户数据的方法。我想念那里吗?我也愿意直接编辑.ui文件的XML以在需要时添加该属性,但是我不知道该属性名称是什么。我可以在这里使用吗?目前,我正在将数据添加到代码中,但对我来说似乎不是正确的解决方案。

I'm using Qt Designer (well, Qt Creator actually, but specifically the part derived from Qt Designer), and I've added a few QComboBox items to a dialog with a constant list of items. I need to map the items in the combo box to strings (which are distinct from the displayed strings). The best idea I've come up for it is to use the QComboBox::itemData function to get the needed string from the selected item, but I'm having trouble adding the associated strings to the items. I've looked all over the designer and have not yet seen a way to add the user data. Is there one there that I'm missing? I'm also willing to directly edit the XML of the .ui file to add the property if needed, but I can't figure out what the property name would be. Is there one that I can use here? Currently I'm adding the data in code, but it doesn't seem like the correct solution to me.

推荐答案

好,因此,我实际上浏览了uic的源代码,并找到了处理QComboBox的位置。从Qt的当前版本(so 5.5.1)开始,不支持通过.ui文件设置项目的数据属性。我可能会将其作为功能请求,但目前尚不支持。

Ok, so I actually went through the source code of the uic and found the spot that handles QComboBox. As of the current version of Qt (so 5.5.1), there is no support for setting the data attribute of the items through the .ui files. I may make this a feature request, but for now, it's unsupported.

这篇关于如何从Qt Designer / .ui文件向QComboBox添加项目数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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