[Interest] How to add child items to QStandardItemModel?
Anisha kaul
anisha.kaul.1983 at gmail.com
Mon Jan 4 13:02:51 CET 2021
Well, I got the answer shortly after posting here:
Here is it:
........
QStandardItemModel model;
QStandardItem *item1 = new QStandardItem("File");
item1->appendRows({new QStandardItem("New"), new QStandardItem("Save")});
QStandardItem *item2 = new QStandardItem("Edit");
item2->appendRows({new QStandardItem("Cut")});
model.appendRow(item1);
model.appendRow(item2);
........
On Mon, Jan 4, 2021 at 4:58 PM Anisha kaul <anisha.kaul.1983 at gmail.com>
wrote:
> Greetings,
>
> Idea is to have something like:
>
> > File
> New
> Save
> >Edit
> Cut
>
>
> I have:
>
> int main( int argc, char *argv[] )
> {
> .........
>
> QStandardItemModel model;
>
> QStandardItem *parentItem0 = model.invisibleRootItem();
>
>
> QStandardItem *file_item = new QStandardItem(QString("File"));
>
>
> QStandardItem *new_ = new QStandardItem(QString("New"));
>
> file_item->setChild(1, new_);
>
>
> parentItem0 = file_item;
>
>
> parentItem0->appendRow( file_item );
>
> ..........
> }
>
> This is not giving me anything.
> What is the way to add child items to parent items?
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210104/470bcc08/attachment.html>
More information about the Interest
mailing list