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 item Line with Line Edit.
Forum Updated to NodeBB v4.3 + New Features

Move item Line with Line Edit.

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 2.3k Views 1 Watching
  • 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

    Hi everyone.
    First of all thanks for helping me.

    I have some LineItems in a Scene represented by QGraphicsView.
    I would like to add 4 LineEdit and one button.

    The idea is the next:
    the Line Edits are: right, left, up, down.
    The button is: move lines.

    If the user selects and item and put for example: 3 in right and 0 in the left, up and down. The line selected is moved 3 coordinates in X to the right.

    I thought that I can do that If I can access to coordinates of selected items and then just add the number of user puts in LIneEdit.

    but how can I access to that¿

    I add lines with:

    line = scene->addLine(x_start,y_start,x_end,y_end, red);
    

    Thanks a lot!

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Alvaro.sal
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        hi
        "but how can I access to that¿"

        I assume you mean the line?
        If selected then u can get it via
        http://doc.qt.io/qt-5/qgraphicsscene.html#selectedItems

        Note: that you might need to make the item selecteable
        http://doc.qt.io/qt-5/qgraphicsitem.html#setFlags
        QGraphicsItem::ItemIsSelectable

        AlvaroSA 1 Reply Last reply
        1
        • mrjjM mrjj

          hi
          "but how can I access to that¿"

          I assume you mean the line?
          If selected then u can get it via
          http://doc.qt.io/qt-5/qgraphicsscene.html#selectedItems

          Note: that you might need to make the item selecteable
          http://doc.qt.io/qt-5/qgraphicsitem.html#setFlags
          QGraphicsItem::ItemIsSelectable

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

          @mrjj Thanks for answering.

          Yes, the line selected or lines selected.
          But I need the coordinates of the line (x_start, y_start, x_end,y_end)
          I did this:

          QList<QGraphicsItem*>a;
              a = scene->selectedItems();
          
              int num_item_selected;
              num_item_selected = a.size(); //Num of items selected.
          
              for (int i=0; i<num_item_selected; i++)
              {
                  QRectF itemBR = a.value(i)->boundingRect();
                  QPointF sceneBR = a.value(i)->scenePos();
                  //std::cout << sceneBR << std::endl;
              }
          
          

          but I can not get the coordinates...

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

            It seems fine
            Did you read about
            http://doc.qt.io/qt-5/graphicsview.html#the-graphics-view-coordinate-system

            scenePos() is correct so you must be getting other values than
            expected?

            If you cast to an actual QGraphicsLineItem

            QGraphicsLineItem * line=qobject_cast<QGraphicsLineItem * >(a.value(i));
            if ( line ){
            http://doc.qt.io/qt-5/qgraphicslineitem.html#line
            }
            Maybe those values are the ones you expect ?

            AlvaroSA 1 Reply Last reply
            1
            • mrjjM mrjj

              It seems fine
              Did you read about
              http://doc.qt.io/qt-5/graphicsview.html#the-graphics-view-coordinate-system

              scenePos() is correct so you must be getting other values than
              expected?

              If you cast to an actual QGraphicsLineItem

              QGraphicsLineItem * line=qobject_cast<QGraphicsLineItem * >(a.value(i));
              if ( line ){
              http://doc.qt.io/qt-5/qgraphicslineitem.html#line
              }
              Maybe those values are the ones you expect ?

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

              @mrjj Yes, the scenePost() retunr always 0,0 ... It does not matter what line I select, the value is always 0,0 ...

              When I write your code it return me an error which is:

              error: no matching function for call to 'qobject_cast(QGraphicsItem*)'
              QGraphicsLineItem * linea =qobject_cast<QGraphicsLineItem * >(a.value(i));
              ^

                      QGraphicsLineItem * linea =qobject_cast<QGraphicsLineItem * >(a.value(i));
                      if (linea)
                      {
                          linea->line;
                      }
              
              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @AlvaroS said:
                oh sorry
                try with qgraphicsitem_cast

                AlvaroSA 1 Reply Last reply
                0
                • mrjjM mrjj

                  @AlvaroS said:
                  oh sorry
                  try with qgraphicsitem_cast

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

                  @mrjj That works fine.
                  Thanks a lot!!!

                  mrjjM 1 Reply Last reply
                  0
                  • AlvaroSA AlvaroS

                    @mrjj That works fine.
                    Thanks a lot!!!

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @AlvaroS
                    super. :)
                    If possible please mark as solved using the topic button.

                    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