Naruto
Naruto

Reputation: 9634

Problem in inserting element to listview in QT

HI..

i want to add elements dynamically to listview in QT for symbian OS, i have set of delegate methods associated with listview.

if i add elements statically, the control comes to delegate methods, and view is perfect.

but if i add dynamically, control is not at all coming to delegate methods.

i don't no how to do it. ill place here some sample code, that how i am adding elements.

this is how i am setting the view,

 MylistView = new QListView();

 QDesktopWidget* desktopWidget = QApplication::desktop();
 QRect clientRect = desktopWidget->geometry();

        MylistView->setMinimumSize(QSize(clientRect.width()-7,clientRect.height()-1));

     MylistView->setViewMode(QListView::ListMode);
     MylistView->setMovement(QListView::Free);
     MylistView->setItemDelegate(new ItemDeligate(MylistView));
     MylistView->setSelectionMode(QAbstractItemView::SingleSelection);
     bool val =GreenPixmap.load(":/new/prefix1/temp/test.png");

     ListModel = new QStandardItemModel();
     ListModel->appendColumn(ItemList);

     MylistView->setModel(ListModel); 
     Listlayout.addWidget(MylistView);
     Listlayout.addWidget(MylistView);
     this->setLayout(&Listlayout);
     AddItemMenu = new QAction("Add",this);                  
     menuBar()->addAction(AddItemMenu);      
     val = connect(AddItemMenu,SIGNAL(triggered()),this,SLOT(addItem()));

This is how i am adding dynamically when the click event occurs, (i.e dynamically adding items)

    QStandardItem *Items = new QStandardItem(QIcon(GreenPixmap),"Avatar");
        Items->setData("WAKE UP",ItemDeligate::SubTextRole);
        ItemList.append(Items);

        ListModel->appendColumn(ItemList);

please suggest me, what mistake i am doing in adding elemetns

Upvotes: 1

Views: 7193

Answers (1)

Andy M
Andy M

Reputation: 6065

I just made this quick example in my app, it's working, maybe it will gibe you an hint :

QStandardItem* Items = new QStandardItem("Avatar");
QStandardItemModel* ListModel = new QStandardItemModel();
ListModel->appendRow(Items);

listView->setModel(ListModel);

In summary, you should simply append a row on your model ! It should fix your problem !

If I missed something, let me know !

Upvotes: 3

Related Questions