1. <tfoot id='vcQYS'></tfoot>

      <i id='vcQYS'><tr id='vcQYS'><dt id='vcQYS'><q id='vcQYS'><span id='vcQYS'><b id='vcQYS'><form id='vcQYS'><ins id='vcQYS'></ins><ul id='vcQYS'></ul><sub id='vcQYS'></sub></form><legend id='vcQYS'></legend><bdo id='vcQYS'><pre id='vcQYS'><center id='vcQYS'></center></pre></bdo></b><th id='vcQYS'></th></span></q></dt></tr></i><div id='vcQYS'><tfoot id='vcQYS'></tfoot><dl id='vcQYS'><fieldset id='vcQYS'></fieldset></dl></div>

        <small id='vcQYS'></small><noframes id='vcQYS'>

          <bdo id='vcQYS'></bdo><ul id='vcQYS'></ul>
        <legend id='vcQYS'><style id='vcQYS'><dir id='vcQYS'><q id='vcQYS'></q></dir></style></legend>

        为树视图创建 Qt 模型

        Creating Qt models for tree views(为树视图创建 Qt 模型)

          <tfoot id='BMJrD'></tfoot>

            <small id='BMJrD'></small><noframes id='BMJrD'>

              <tbody id='BMJrD'></tbody>
              <bdo id='BMJrD'></bdo><ul id='BMJrD'></ul>
              <i id='BMJrD'><tr id='BMJrD'><dt id='BMJrD'><q id='BMJrD'><span id='BMJrD'><b id='BMJrD'><form id='BMJrD'><ins id='BMJrD'></ins><ul id='BMJrD'></ul><sub id='BMJrD'></sub></form><legend id='BMJrD'></legend><bdo id='BMJrD'><pre id='BMJrD'><center id='BMJrD'></center></pre></bdo></b><th id='BMJrD'></th></span></q></dt></tr></i><div id='BMJrD'><tfoot id='BMJrD'></tfoot><dl id='BMJrD'><fieldset id='BMJrD'></fieldset></dl></div>
              <legend id='BMJrD'><style id='BMJrD'><dir id='BMJrD'><q id='BMJrD'></q></dir></style></legend>

                • 本文介绍了为树视图创建 Qt 模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在用 Qt(使用 C++)编写一个应用程序,我需要在树视图中表示一个对象结构.一种方法是为此创建一个模型,但在阅读了有关该主题的 Qt 文档后,我仍然很困惑.

                  I'm writing an application in Qt (with C++) and I need to represent an object structure in a tree view. One of the ways to do this is to create a model for this, but I'm still quite confused after reading the Qt documentation about the subject.

                  我拥有的结构"非常简单 - 有一个 Project 对象,它在 std::vector 容器中保存 Task 对象.这些任务也可以包含子任务.

                  The "structure" I have is pretty simple - there's a Project object that holds Task objects in a std::vector container. These tasks can also hold child tasks.

                  我已经编写了读取 & 的方法使用 Qt 的 XML 类将这些项目写入/从 XML 文件写入.

                  I've already written methods to read & write these projects to/from XML files using Qt's XML classes.

                  是否有更多文档或推荐阅读"可用于从头开始创建模型?您建议我如何开始实施?

                  Is there any more documentation or "recommended reading" for creating models from scratch? How do you recommend I start implementing this?

                  推荐答案

                  作为 Virgil 在对该问题的评论中所说的替代方案,您可以使用 QStandardItemModel 类用于您的模型,然后使用此类构建您的树.下面是一个例子:

                  As an alternative to what was said by Virgil in a comment to the question, you could use QStandardItemModel class for your model and just build your tree using this class. Below is an example:

                  QStandardItemModel* model = new QStandardItemModel();
                  
                  QStandardItem* item0 = new QStandardItem(QIcon("test.png"), "1 first item");
                  QStandardItem* item1 = new QStandardItem(QIcon("test.png"), "2 second item");
                  QStandardItem* item3 = new QStandardItem(QIcon("test.png"), "3 third item");
                  QStandardItem* item4 = new QStandardItem("4 forth item");
                  
                  model->appendRow(item0);
                  item0->appendRow(item3);
                  item0->appendRow(item4);
                  model->appendRow(item1);
                  
                  ui->treeView->setModel(model);
                  

                  当UI(视图)被销毁时,删除model.文档:

                  When the UI (view) is destroyed, delete model. Documentation:

                  • https://doc.qt.io/qt-5/qstandarditemmodel.html
                  • https://doc.qt.io/qt-5/qstandarditem.html

                  这篇关于为树视图创建 Qt 模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                  <legend id='8Cr3I'><style id='8Cr3I'><dir id='8Cr3I'><q id='8Cr3I'></q></dir></style></legend>

                    <bdo id='8Cr3I'></bdo><ul id='8Cr3I'></ul>
                  • <small id='8Cr3I'></small><noframes id='8Cr3I'>

                    <i id='8Cr3I'><tr id='8Cr3I'><dt id='8Cr3I'><q id='8Cr3I'><span id='8Cr3I'><b id='8Cr3I'><form id='8Cr3I'><ins id='8Cr3I'></ins><ul id='8Cr3I'></ul><sub id='8Cr3I'></sub></form><legend id='8Cr3I'></legend><bdo id='8Cr3I'><pre id='8Cr3I'><center id='8Cr3I'></center></pre></bdo></b><th id='8Cr3I'></th></span></q></dt></tr></i><div id='8Cr3I'><tfoot id='8Cr3I'></tfoot><dl id='8Cr3I'><fieldset id='8Cr3I'></fieldset></dl></div>
                      <tbody id='8Cr3I'></tbody>

                          <tfoot id='8Cr3I'></tfoot>