Results 1 to 5 of 5

Thread: 2 QGraphicsScene and connect between them

  1. #1
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default 2 QGraphicsScene and connect between them

    Hi I have 2 classes and I would like to have this situation.
    When I use "releaseclick" in first scene, then I want to do some reaction in 2nd scene. I dont know, how create it
    Please help

  2. #2
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: 2 QGraphicsScene and connect between them

    Quote Originally Posted by Noxxik View Post
    Hi I have 2 classes and I would like to have this situation.
    When I use "releaseclick" in first scene, then I want to do some reaction in 2nd scene. I dont know, how create it
    Please help
    QGraphicsScene is an QObject that can have signal/slot connection...

  3. #3
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: 2 QGraphicsScene and connect between them

    Quote Originally Posted by lni View Post
    QGraphicsScene is an QObject that can have signal/slot connection...
    thanks, but I dont know, which signal I could use...
    Qt Code:
    1. textureView = new TextureView();
    2. .
    3. .
    4. .
    5. TextureView::TextureView(QWidget *parent)
    6. : QGraphicsView(parent)
    7. {
    8. textureScene = new QGraphicsScene(this);
    9. textureScene->setSceneRect(0, 0, 180, 200);
    10. setScene(textureScene);
    11. addItems();
    12. }
    13.  
    14. void TextureView::addItems()
    15. {
    16. ImageItem *image;
    17. image = new ImageItem(1, QPixmap(":/images/background1"/* + i*/));
    18. image->setPos(0, 0);
    19. textureScene->addItem(image);
    20. }
    21. void TextureView::mouseReleaseEvent(QMouseEvent *event)
    22. {
    23. if (QGraphicsItem *item = itemAt(event->pos())) {
    24. if (ImageItem *image = qgraphicsitem_cast<ImageItem *>(item))
    25. setId(image->id());
    26. }
    27. QGraphicsView::mouseReleaseEvent(event);
    28. }
    29. void TextureView::setId(int id)
    30. {
    31. itemId=id;
    32. }
    33.  
    34. ImageItem::ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent,
    35. : QGraphicsPixmapItem(pixmap, parent, scene)
    36. {
    37. recordId = id;
    38. }
    To copy to clipboard, switch view to plain text mode 
    I would like to make reaction on mouseReleaseEvent but this proteeted function isnot singal. Could you help me please again? Thank you very much

  4. #4
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: 2 QGraphicsScene and connect between them

    I am trying to write own singnal and slot for connection between 2 scene

    Qt Code:
    1. connect(textureView, SIGNAL(textureId(int)), scene, SLOT(getTextureId(int)));
    To copy to clipboard, switch view to plain text mode 

    how should write this signal? How I get information, which integer will be send to slot?
    I cannot imagine how to set integer, in order to send to slot

    when I tried it now, I have...
    Qt Code:
    1. void TextureView::textureId(int id)
    2. {
    3.  
    4. }
    To copy to clipboard, switch view to plain text mode 
    yes it is free because I dont know, how to set integer, which will be send

    So I tried to compiled and in moc_*.cpp file It create me
    Qt Code:
    1. void TextureView::textureId(int _t1)
    2. {
    3. void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
    4. QMetaObject::activate(this, &staticMetaObject, 0, _a);
    5. }
    To copy to clipboard, switch view to plain text mode 
    but compiler wrote error that in moc_*.coo is first definition of this signal.
    Please help me, I didnot wrote any own signals thanks

    edit:
    I would like to send itemId to scene to slot SLOT(getTextureId(int))
    Qt Code:
    1. void TextureView::setId(int id)
    2. {
    3. itemId=id;
    4. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Noxxik; 27th February 2009 at 13:17.

  5. #5
    Join Date
    Feb 2009
    Posts
    53
    Thanks
    5

    Default Re: 2 QGraphicsScene and connect between them

    my problem fixed you can lock this thread
    It was my stupid mistake...

Similar Threads

  1. QGraphicsScene signal
    By eijnuhs in forum Qt Programming
    Replies: 1
    Last Post: 22nd September 2008, 07:04
  2. best way to connect QGraphicsTextItem to a QEditLine
    By mooreaa in forum Qt Programming
    Replies: 5
    Last Post: 2nd August 2008, 11:33

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.