add child item in list view
Hi,
i create list view , i set model to the list like that
Code:
listView->setModel( model );
i createthe model like that
Code:
void MainWindow::createModel()
{
model
->setHorizontalHeaderLabels
( QStringList() <<
"liste" );
createModelItems();
}
void MainWindow::createModelItems()
{
choiceList << "conf1" << "conf2" << "conf3";
foreach
( QString str, choiceList
){ // parent pItem->setTristate( true );
model->appendRow( pItem );
}
}
and i added new item like that with signal slot
the sig,al is
Code:
void MainWindow::add(vector3 point)
{
nb_mark++;
emit itemAded(item);
}
the slot is
Code:
{
model->appendRow( pItem );
}
but the problem is that it add to me new item and that's not what i want
i want to add the new item as child of an item of the "chois list"
i know that i must add this infiormation in the signal , but how i do that ? have you an idea ?
Re: add child item in list view
Quote:
and i added new item like that with signal slot
the sig,al is
Do not implement/define signal method. (Qt will define it). Move the code in the signal into slot and remove the signal definition.
Quote:
i want to add the new item as child of an item of the "chois list"
List items cannot have child item, you should use Tree (TreeView) if you want to add new items as children.
Re: add child item in list view
hi,
Quote:
Do not implement/define signal method. (Qt will define it). Move the code in the signal into slot and remove the signal definition.
no i must add it , because it's important and there is another things i must made it in the signal.
Quote:
List items cannot have child item, you should use Tree (TreeView) if you want to add new items as children.
if i use treeview i will change à lot the code ?
another thing i see in some exemple thy used listview with child
Code:
void MainWindow::createModelItems()
{
choiceList << "Alpha" << "Beta" << "Charlie";
optionList << "Opt1" << "Opt2" << "Opt3";
foreach
( QString str, choiceList
){ // parent pItem->setCheckable( true );
pItem->setTristate( true );
foreach
( QString str, optionList
){ // children cItem->setCheckable( true );
pItem->appendRow( cItem );
}
model->appendRow( pItem );
}
}
Re: add child item in list view
Quote:
hi,
Quote:
Do not implement/define signal method. (Qt will define it). Move the code in the signal into slot and remove the signal definition.
no i must add it , because it's important and there is another things i must made it in the signal.
The signal still exists, I mean only the signal declaration should be there (class.h), and signal definition/implementation (class.cpp) should not exists. Qt framework creates the implementation for you.
Quote:
Quote:
List items cannot have child item, you should use Tree (TreeView) if you want to add new items as children.
if i use treeview i will change à lot the code ?
another thing i see in some exemple thy used listview with child
The code snipet is using QStandardItemModel, this model has to set on a QTreeView.