Move line in a scene



  • Hello everyone!
    First of all thanks a lot for helping me and reading this post.

    I would like to move the line position in a scene (not to reomive it and then add it).

    I did this:

            QGraphicsItem* my_item = a.value(i); //Item (i) selected
            QGraphicsLineItem *linea_moved = qgraphicsitem_cast<QGraphicsLineItem *>(my_item); // Line moved is a line that user has selected
    
                QPointF pstart;
                QPointF pend;
    
                pstart.setX(XStart_line-ui->Move_left->text().toDouble()+ui->Move_right->text().toDouble());
                pstart.setY(YStart_line+ui->Move_down->text().toDouble()-ui->Move_up->text().toDouble());
    
                pend.setX(XEnd_line-ui->Move_left->text().toDouble()+ui->Move_right->text().toDouble());
                pend.setY(YEnd_line+ui->Move_down->text().toDouble()-ui->Move_up->text().toDouble());
    
                linea_moved->line().setPoints(pstart,pend);
    

    The points line change but the problem is that the line does not change in the scene...
    So how can I do that?

    thanks a lot!!!


  • Qt Champions 2016

    @AlvaroS said:

    linea_moved->line().setPoints(pstart,pend);

    Hi, im no expert but I think you need a setLine
    http://doc.qt.io/qt-4.8/qgraphicslineitem.html#line
    Seems to return a COPY of the line object.

    so I think u need something like:
    QLineF newline= linea_moved->line();
    newline.setPoints(pstart,pend);
    linea_moved->setLine(newline);



  • @mrjj hi my friend. You helped me a lot. That works fine!!!!!!!
    Superb!!!!!!!
    Thanks again


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.