Results 1 to 9 of 9

Thread: How to make a list of QGraphicsItems on the scene

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to make a list of QGraphicsItems on the scene

    hi,
    I 'm trying to make a queue of QGraphicsRectItems on the scene after have moving each of them forwards .I used the QGraphicsItemGroup but i cannot run it.
    may someone help me to solve this problem please?
    thanks in advance.
    the code looks like this:


    Container.h
    Qt Code:
    1. class Container: public QGraphicsRectItem
    2. {
    3. Q_OBJECT
    4. public:
    5. Container(QGraphicsItem* parent=0, int x, int y);
    6. void advance();
    7. private:
    8. QTimeLine * timeline;
    9. };
    To copy to clipboard, switch view to plain text mode 
    Container.cpp
    Qt Code:
    1. #include"container.h"
    2.  
    3. Container::Container(QGraphicsItem* parent, int x=0, int y=0):QGraphicsRectItem(parent)
    4. {QColor color(0,0,100);
    5. Qpen p(color);
    6. p.setWidht(2);
    7. QBrush(brush);
    8. setRect(x,y,100,60);
    9. show();
    10.  
    11. }
    12.  
    13. Container::advance(){
    14.  
    15.  
    16. timeline= new QTimeLine(5000);
    17. anim->setItem(this);
    18. for (qreal i=0.0;i<500.0;i++){
    19. anim->setTranslationAt(i/500.0,0.0,i);
    20. }
    21. anim->setTimeLine(timeline);
    22. timeline->setDirection(QTimeLine::Backward);
    23. timeline->setUpdateInterval(1000/10);
    24. timeline->setLoopCount(1);
    25. timeline->setDuration(50000);
    26.  
    27. }
    To copy to clipboard, switch view to plain text mode 
    MainGui.h
    Qt Code:
    1. class MainGui: public QWidget
    2. {
    3. public:
    4. MainGui(...);
    5. private:
    6. QGraphicsItemGroup* itemGroup;
    7. };
    To copy to clipboard, switch view to plain text mode 
    MainGui.cpp
    Qt Code:
    1. #include "container.h"
    2.  
    3. Container*c1= new Container (0,0,0);
    4. Container*c2= new Container (0,0,0);
    5.  
    6. scene= new Scene(this);
    7. itemGroup= scene->createItemGroup(scene->selectedItems());
    8. c1->advance();
    9. itemGroup->addToGroup(c1);
    10. c1-> setZValue(405.0);/*I'm trying to separate the RectItems so that their do not overlap because i want them to be range in a queue. into the scene.*/
    11.  
    12. c2->advance();
    13. itemGroup->addToGroup(c2);
    14. c2-> setZValue(400.0);
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 9th June 2008 at 17:05. Reason: missing [code] tags

Similar Threads

  1. make QTableView work as a multi-column list view
    By wesley in forum Qt Programming
    Replies: 1
    Last Post: 11th March 2008, 14:43
  2. Replies: 1
    Last Post: 14th May 2007, 14:55
  3. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57

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.