views:

627

answers:

1

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

+1  A: 

Hey,

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 !

Andy M
Hey andy, thanks fr the reply.i am facing two main problems, hope i will get some help from ur end1) if i create a listview and set to layout in a class, which is derived from Qmainwindow it is not working. but if i do the same in a class derived from qwidget it works well.2)i am facing problem in adding menu to widget, which is derived from qwidget class.if u know the soln fr the above, pls let me know..
Shadow
1) QMainwindow has a centralWidget() method that you could use to get a widget, and then a layout, and therefore, add your list the way you want. Don't you think so ?
Andy M
2) What kind of trouble do you have with the menu ? Could you describe it a little bit more ?
Andy M
Hey.. thats nice... one problem solved..i hd no idea about central widgets, now i got it.. ThanksMenu means normal menu comes in mobile i.e popup menu.if we tap on a menu at the bottom we get menu right that one i want.if we have a class derived from Qmainwindow we get menuBar() function directly, we can also add menu. but its not the case for class derived from Qwidget in that we need to set Menubar right.i am not getting how to set it?
Shadow
Okay, great, we're going forward... erm, I'm not sure to get it, do you try to add a QMenubar on a QWidget ? Do you want something like a right-click menu or ? Maybe a screenshot would help ?
Andy M
do you try to add a QMenubar on a QWidget ? yup.. i wan this only, how to achive it..manually creating menubar and setting to widget?no right click menu
Shadow
I didn't test it but did you already try creating a new QMenubar like this: QMenuBar* pMyMenuBar = new QMenuBar(MyWidget); ?
Andy M
Ya.. i tried like that.. but i didnt get any results..any way, ill try digging and i will tell you if i get it..suppose if you are free or if u get any were else please tell me..Thanks you once again
Shadow