如何使用 QCombobox 模型

发布于 2024-09-16 12:40:05 字数 227 浏览 3 评论 0原文

我想使用QCombobox作为JavaSwingCombobox。所以我需要使用 Model 来保存我的对象。我如何将我的对象保存在 QCombobox 中。 (我认为我应该在模型中保存数据,因为 QCombobox 是根据 MVC 模式设计的......) 任何帮助将不胜感激。

I want to use QCombobox as a the Combobox of Swing in Java. So i need to use Model for holding my object. How can i hold my object in QCombobox. (I think that I should hold data in Model because QCombobox was designed according to MVC Pattern ... )
Any help will be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尬尬 2024-09-23 12:40:05

根据您想要使用 QComboBox 显示的内容,您需要编写自己的模型,继承 QAbstractListModel,重新实现 rowCount()数据()

然后,使用 QComboBox::setModel() 使 QComboBox 显示它。

如果您只想显示字符串,可以使用 QStringListModel ,随 Qt 一起提供。

Depending on what you want to display with your QComboBox, you'll need to write your own model, inheriting QAbstractListModel, reimplementing rowCount()and data().

Then, use QComboBox::setModel() to make the QComboBox display it.

If you just want to display strings, you can use a QStringListModel, provided with Qt.

勿忘初心 2024-09-23 12:40:05

您可以使用 将模型添加到您的 QCombobox setModel 函数。您可以使用预定义的模型,也可以通过继承 QAbstractItemModel

您的模型将包含您的对象以将显示与数据分开。

You can add a model to your QCombobox by using the setModel function. You can use a predefined model or create your own by inheriting from QAbstractItemModel.

Your model will contain your object to separate display from data.

一个人练习一个人 2024-09-23 12:40:05

Qt 使用 MVC 的简化版本,其中只有模型/视图部分。

如果不需要,您可以使用 QAbstractItemModel 提供的子类之一任何专门的行为,使用哪一种行为取决于您是将数据保存在文件系统中还是内存中的数据结构中。

您应该阅读模型/视图编程的整个部分在 Qt 文档中。

Qt uses a simplified version of MVC which only has the Model / View parts.

You can use one of the provided subclasses of QAbstractItemModel if you don't need any specialized behaviour, which one to use depends on whether you keep your data in a file system or a data structure in memory.

You should read up the whole section on model/view programming in the Qt documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文