Results 1 to 2 of 2

Thread: passing data between parent and child widget

  1. #1
    Join Date
    Feb 2014
    Posts
    26
    Qt products
    Qt5
    Platforms
    Windows

    Default passing data between parent and child widget

    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.

  2. #2
    Join Date
    Mar 2014
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: passing data between parent and child widget

    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.

Similar Threads

  1. How to resize parent widget when child widget is resized
    By ainne810329 in forum Qt Programming
    Replies: 4
    Last Post: 29th November 2011, 07:47
  2. Replies: 1
    Last Post: 11th March 2011, 19:34
  3. Replies: 12
    Last Post: 7th January 2011, 13:21
  4. Replies: 7
    Last Post: 14th January 2010, 08:47
  5. Replies: 4
    Last Post: 3rd October 2009, 08:19

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.