Results 1 to 18 of 18

Thread: How to move an item on a GraphicsScene

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 move an item on a GraphicsScene

    Hi,
    II'm trying to move a GraphicsItem on a GraphicsScene using moveBy()Function but nothing moves on the screen , may someone help me to achieve this ?
    Thanks in advance
    here is the Programmcode i tried to write :
    -------
    Qt Code:
    1. class Container: public QGraphicsRectItem
    2. {
    3. public:
    4. Container(QGraphicsItem* parent=0, intx, int y);
    5. };
    6. Container::Container(QGraphicsItem* parent, intx=0, int y=0): QGraphicsRectItem(parent)
    7. {QColor color (0,0,100);
    8. QPen p(color);
    9. p.setWidth(2);
    10. QBrush brush(QColor(0,160,0));
    11. setPen(p);
    12. setBrush(brush);
    13. setRect()x,y,100,60;
    14. show();
    15. }
    To copy to clipboard, switch view to plain text mode 
    --------
    Qt Code:
    1. #include"Container.h"
    2. class Scene: public QGraphicsScene
    3. {
    4. public:
    5. Scene(QWidget* parent=0);
    6. Container*container;
    7. };
    8. Scene::Scene(QWidget* parent):QGraphicsScene(parent)
    9. {
    10. QBrush brush(QColor(180,180,220), Qt::Dense4Pattern);
    11. setBackgroundBrush(brush);
    12. }
    To copy to clipboard, switch view to plain text mode 
    --------
    mainGui class
    Qt Code:
    1. #include"include/gui/mainGui.h"
    2. #include"include/gui/Scene.h"
    3. #include"include/gui/container.h"
    4. class MainGui:public QWidget
    5. {
    6. Q_OBJECT
    7. public:
    8. MainGui(QWidget*parent=0);
    9. private:
    10. };
    11. MainGui::MainGui(QWidget *parent):QWidget(parent)
    12. {
    13. scene=newScene(this);
    14. Container*c1= new Container(0,0,0);
    15. // I want the item to move step by step after any 1000 ms on the Screen
    16. QMoveEvent *event;
    17. int x=event->pos().x();
    18. int y=event->pos().y();
    19. c1->moveBy((qreal)x,(qreal)y);
    20. startTimer(1000);
    21. c1->addItem(c1);
    22. scene->addLine(-5, -200, -5, 200);
    23. scene->addLine(105, -200,105, 200);
    24. scene->advance();
    25. QGraphicsView *view =new QGraphicsView (scene);
    26. QGridLayout *layout= new QGridLayout();
    27. layout->addWidget(view);
    28. setLayou(layout);
    29. view->show();
    30. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jacek; 3rd June 2008 at 22:41. Reason: missing [code] tags

Similar Threads

  1. Move and resize with layout
    By waediowa in forum Qt Programming
    Replies: 0
    Last Post: 14th May 2008, 08:16
  2. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  3. Replies: 1
    Last Post: 19th April 2007, 22:23
  4. how to display full tree item name on mouse move ?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 15th November 2006, 08:41
  5. how change the QListBox item position by pixel
    By roy_skyx in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2006, 01:34

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.