Results 1 to 2 of 2

Thread: Problem ,Adding QGraphicsItems in GraphicsScene

  1. #1
    Join Date
    Jan 2008
    Posts
    91
    Thanks
    8

    Default Problem ,Adding QGraphicsItems in GraphicsScene

    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.

    Qt Code:
    1. class GraphicsViewManager : public QObject {
    2. Q_OBJECT
    3. public:
    4. GraphicsViewManager();
    5. virtual ~GraphicsViewManager();
    6. std::vector <GraphicItem*> LoadList(std::list <Item> Liste);
    7. GraphicItem *item;
    8. private:
    9. std::vector <GraphicItem*> GItems;
    10. std::vector <GraphicItem*>::iterator Itr;
    11. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void TestView::SetList(std::list <Item> Liste)
    2. {
    3. _Liste = Liste;
    4. Items = Manager->LoadList(_Liste); //GraphicsViewManager *Manager;
    5. for(int i=0;i<Items.size();i++)
    6. m_GraphicsScene->addItem(Items[i]);
    7. }
    To copy to clipboard, switch view to plain text mode 



    Qt Code:
    1. std::vector <GraphicItem*> GraphicsViewManager::LoadList(std::list <Item> Liste)
    2. {
    3. GItems.clear();
    4.  
    5. for(std::list<Item>::iterator itr=Liste.begin();itr != Liste.end();itr++)
    6. {
    7. QPixmap pixmap(QString().fromUtf8((char*)itr->PicturesUrl.front().data()));
    8. item = new GraphicItem(pixmap);
    9. GItems.push_back(item);
    10. }
    11. SetXYData();
    12. return GItems;
    13. }
    To copy to clipboard, switch view to plain text mode 


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

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem ,Adding QGraphicsItems in GraphicsScene

    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

Similar Threads

  1. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  2. Qt4/Mac: funny problem with QGraphicsItems
    By fabietto in forum Qt Programming
    Replies: 2
    Last Post: 22nd November 2007, 11:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.