PDA

View Full Version : 2 QGraphicsScene and connect between them



Noxxik
27th February 2009, 01:15
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

lni
27th February 2009, 05:38
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...

Noxxik
27th February 2009, 11:07
QGraphicsScene is an QObject that can have signal/slot connection...
thanks, but I dont know, which signal I could use...

textureView = new TextureView();
.
.
.
TextureView::TextureView(QWidget *parent)
: QGraphicsView(parent)
{
textureScene = new QGraphicsScene(this);
textureScene->setSceneRect(0, 0, 180, 200);
setScene(textureScene);
addItems();
}

void TextureView::addItems()
{
ImageItem *image;
image = new ImageItem(1, QPixmap(":/images/background1"/* + i*/));
image->setPos(0, 0);
textureScene->addItem(image);
}
void TextureView::mouseReleaseEvent(QMouseEvent *event)
{
if (QGraphicsItem *item = itemAt(event->pos())) {
if (ImageItem *image = qgraphicsitem_cast<ImageItem *>(item))
setId(image->id());
}
QGraphicsView::mouseReleaseEvent(event);
}
void TextureView::setId(int id)
{
itemId=id;
}

ImageItem::ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent,
QGraphicsScene *scene)
: QGraphicsPixmapItem(pixmap, parent, scene)
{
recordId = id;
}

I would like to make reaction on mouseReleaseEvent but this proteeted function isnot singal. Could you help me please again? Thank you very much

Noxxik
27th February 2009, 13:33
I am trying to write own singnal and slot for connection between 2 scene


connect(textureView, SIGNAL(textureId(int)), scene, SLOT(getTextureId(int)));

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...

void TextureView::textureId(int id)
{

}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

void TextureView::textureId(int _t1)
{
void *_a[] = { 0, const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };
QMetaObject::activate(this, &staticMetaObject, 0, _a);
}
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))

void TextureView::setId(int id)
{
itemId=id;
}

Noxxik
27th February 2009, 15:19
my problem fixed :) you can lock this thread :)
It was my stupid mistake... :mad: :o