C++ 在 Qt 组合框中设置项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13586303/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:30:45  来源:igfitidea点击:

Setting items in Qt combo box

c++qtcombobox

提问by danial weaber

I'm very new to Qt. I'm following this tutorial http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html. There is a small mistake in this tutorial. Though it adds a combo box entry, text is not set. Can somebody tell me how to initialize the combo box, correctly.

我对 Qt 很陌生。我正在关注本教程http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html。本教程有一个小错误。尽管它添加了一个组合框条目,但未设置文本。有人可以告诉我如何正确初始化组合框。

Also, can somebody point out me if there are better tutorials for learning Qt ?

另外,如果有更好的学习 Qt 的教程,有人可以指出我吗?

回答by danial weaber

At last, I got the right answer. I have provided it below, hopefully it will be useful to other beginners:

最后,我得到了正确的答案。我在下面提供了它,希望它对其他初学者有用:

QStringList list=(QStringList()<<"red"<<"yellow"<<"blue");
comboBox->addItems(list);

回答by Jeremie

This tutorial is made for Qt 4.2, we are now at Qt 4.8. You should find what you are looking for here http://qt-project.org/doc/qt-4.8/how-to-learn-qt.html

本教程是为 Qt 4.2 制作的,我们现在是 Qt 4.8。你应该在这里找到你要找的东西http://qt-project.org/doc/qt-4.8/how-to-learn-qt.html

Little advice, try not to use Qt creator to design your Gui until you understand how to do it with code, you will do less mistakes (and know what to look for when you do).

一点建议,在你了解如何用代码来做之前,尽量不要使用 Qt creator 来设计你的 Gui,你会犯更少的错误(并且知道在你做的时候要寻找什么)。

回答by user2633954

When your in Qt Designer you could just double click on the QComboBox and an EditComboBox screen will appear. There you just click on the plus or minus sign to easily add items to the list of objects.Hope this helps.This way you don't have to do it with code though.

当您在 Qt 设计器中时,您只需双击 QComboBox,就会出现一个 EditComboBox 屏幕。在那里,您只需单击加号或减号即可轻松地将项目添加到对象列表中。希望这会有所帮助。不过这样您就不必使用代码来执行此操作了。