Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Move line in a scene

Move line in a scene

Scheduled Pinned Locked Moved Solved General and Desktop
scenelinemove
3 Posts 2 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AlvaroSA Offline
    AlvaroSA Offline
    AlvaroS
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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);

      AlvaroSA 1 Reply Last reply
      0
      • mrjjM mrjj

        @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);

        AlvaroSA Offline
        AlvaroSA Offline
        AlvaroS
        wrote on last edited by
        #3

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

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved