简体   繁体   English

Qt:如何获取任意索引处的QComboBox项文本(不是当前选择的项)

[英]Qt : How to get QComboBox item text at an arbitrary index (not the currently selected item)

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

Use itemText() method to do this. 使用itemText()方法执行此操作。 Just set needed index. 只需设置所需的索引。

As Marek R pointed, you can get model and get data from this model, but it will be helpful for you when you want to get something more than text( for example get image with Qt::DecorationRole or font with Qt::FontRole ) 正如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#itemText

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM