PDA

View Full Version : passing data between parent and child widget



rakefet
3rd March 2014, 01:11
Hi,


I need help to figure out how to list on my main window the positions of items I am selecting on my scene.
From my main window:
.
.
.
ui->setupUi(this);
QPixmap pix1(image1);
ui->widget1->Scene->addPixmap( pix1 );
QList<QPointF> list1;
QPixmap pix2(image2);
ui->widget2->Scene->addPixmap( pix2 );
QList<QPointF> list2;

From my QGraphicsView:
.
.
.
void MyGraphicsView::mousePressEvent(QMouseEvent * e)
{
if (e->buttons().testFlag(Qt::MidButton))
{
double rad = 2;
QPointF pt = mapToScene(e->pos());
QPen myPen = QPen(Qt::red);
this->Scene->addEllipse(pt.x()-rad, pt.y()-rad, rad*2.0, rad*2.0,
myPen, QBrush(Qt::SolidPattern));
this->list.append(pt);
}
}

1) What I would like to do is something like:
ui->label1->text(str); where str is the position of a new item that was added.
2) Remove an item from the scene if the user selects a point in the same position where an item already exist.
I'll appreciate any guidance.
Thank you.

ma.renaud
5th March 2014, 00:26
You may try to emit a signal with the position as parameter on the mousePressEvent and then catch it with a slot in the main window.