Results 1 to 7 of 7

Thread: Crazy over the QGraphicsScene/Item

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Crazy over the QGraphicsScene/Item

    Did u subclass the pix item ??
    if yes, while handling mousepress event.. try passing it to QGraphicsItem::mousePressEvent ()....

    also how are town and game related ??

  2. #2
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: Crazy over the QGraphicsScene/Item

    Yes I did this:

    Qt Code:
    1. class Town :public QGraphicsPixmapItem {
    2. public:
    3. Town(QPoint p=QPoint(0,0));
    4. void mousePressEvent(QGraphicsSceneMouseEvent* ev);
    5. protected:
    6. QString name;
    7. };
    To copy to clipboard, switch view to plain text mode 

    In the town.cpp file I have

    Qt Code:
    1. void Town::mousePressEvent(QGraphicsSceneMouseEvent* ev)
    2. {
    3. Qt::MouseButtons btn = ev->buttons();
    4. if (btn & Qt::LeftButton)
    5. {
    6. qDebug()<<"You visited Lamerville";
    7. }
    To copy to clipboard, switch view to plain text mode 
    }

    Should I add a line
    Qt Code:
    1. QGraphicsItem::mousePressEvent ();
    To copy to clipboard, switch view to plain text mode 
    to the code? Where? In the beginning of the function?
    Exactly, what will it accomplish?

    town and game is related by populating the game ( a Scene) with towns (Items)

    Qt Code:
    1. QVector<QPoint> cities = map->randomTownPositions(8);
    2. QPoint pos;
    3. Town* t;
    4. foreach (pos, cities)
    5. {
    6. t = new Town(pos);
    7. addItem(t);
    8. towns.push_back(t);
    9. }
    To copy to clipboard, switch view to plain text mode 
    I think the "additem" will be enough, won't it?

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Crazy over the QGraphicsScene/Item

    did u try adding QGraphicsItem::mousePressEvent () to ur mousepressevent ??

  4. #4
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: Crazy over the QGraphicsScene/Item

    Sorry, I did something to solve it. I can't remember right now.
    But I think it was somethign with mousPressEvent.. or.. no. I don't remember what it was.

  5. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 334 Times in 317 Posts

    Default Re: Crazy over the QGraphicsScene/Item

    well.. if u remmeber what u did.. u may post it.. it may benefit me too if ur way is not known

  6. #6
    Join Date
    Feb 2006
    Posts
    209
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13

    Default Re: Crazy over the QGraphicsScene/Item

    I think it was something with adding the item to the scene or setting the parent.

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
  •  
Qt is a trademark of The Qt Company.