c++ - Qt : How to get QComboBox item text at an arbitrary index (not the currently selected item)

标签 c++ qt combobox qcombobox

提取所选 QComboBox 项的文本是众所周知的,但我如何在 QComboBox 中获取任意索引项(不一定是所选项)的文本?

最佳答案

使用 itemText()方法来做到这一点。只需设置所需的索引即可。

作为Marek R指出,你可以得到模型并从这个模型中得到数据,但是当你想要得到比文本更多的东西时它会对你有所帮助(例如用 Qt::DecorationRole 得到图像或用 Qt::FontRole 得到字体)

http://qt-project.org/doc/qt-4.8/qcombobox.html#itemText

http://qt-project.org/doc/qt-4.8/qcombobox.html#model

关于c++ - Qt : How to get QComboBox item text at an arbitrary index (not the currently selected item),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26987281/

相关文章:

c++ - Q工具栏 : Displaying the menu when toolbutton is pressed - DownArrow Issue

c++ - 不能#include <QQuickView>(或<QtQuick>)。

c# - WPF 获取组合框选定的文本(MVVM)

wpf:如何使 ComboBoxItems 在 xaml 中保存整数

c++ - 链接 src/与 CMake 作为库#include'd 与一些 `libname/` 前缀

c++ - 打印出错误的值

c++ - STL vector 和指向 vector 元素的指针

c++ - 将 QGyroscopeReading 转换为 QVector3D 的正确方法是什么?

c++ - 我能告诉我对 `vtable 的 undefined reference 在哪里吗?

wpf - 如何获取 WPF DataGrid 的单元格级别 ComboBox?