PDA

View Full Version : Problem ,Adding QGraphicsItems in GraphicsScene



anafor2004
3rd October 2009, 13:32
Dear Friends,
I have prepared Two classes, First class is TestView class, Which is derived from QGraphicView Item, The other class is GraphicsViewManager Which is responsible for managing Items moving, painting , adding to Scene and replacing.

I am sending Item list to the GraphicsViewManager, then I am creating std::vector type in GraphicsViewManager then returning it to the Testview and TestView adding it to the Scene, but I couldnt see them on scene.


class GraphicsViewManager : public QObject {
Q_OBJECT
public:
GraphicsViewManager();
virtual ~GraphicsViewManager();
std::vector <GraphicItem*> LoadList(std::list <Item> Liste);
GraphicItem *item;
private:
std::vector <GraphicItem*> GItems;
std::vector <GraphicItem*>::iterator Itr;
};


void TestView::SetList(std::list <Item> Liste)
{
_Liste = Liste;
Items = Manager->LoadList(_Liste); //GraphicsViewManager *Manager;
for(int i=0;i<Items.size();i++)
m_GraphicsScene->addItem(Items[i]);
}




std::vector <GraphicItem*> GraphicsViewManager::LoadList(std::list <Item> Liste)
{
GItems.clear();

for(std::list<Item>::iterator itr=Liste.begin();itr != Liste.end();itr++)
{
QPixmap pixmap(QString().fromUtf8((char*)itr->PicturesUrl.front().data()));
item = new GraphicItem(pixmap);
GItems.push_back(item);
}
SetXYData();
return GItems;
}


When I checked the size of Items , size is true but when I added on Scene it doesnt appear.

scascio
4th October 2009, 16:55
In which method the size you check is good.

At first glance I see two possible reasons:
* items are added but not visible
* you didn't call QGraphicsView::setScene with the scene in your derived view