Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved [SOLVED]Move QRectF

    General and Desktop
    qrectf scene
    3
    10
    2346
    Loading More Posts
    • 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.
    • mandruk1331
      mandruk1331 last edited by mandruk1331

      How I can move the QRectF object in the scene, by move I mean move it by setting its coordinates, I have tried QRectF rect; rect.setPos(10,10,100,100); but it still stays in the center of the scene how I can move it?

      Mandruk1331

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        @mandruk1331 said:

        QRectF

        Hmmm.
        Do you mean such item ?
        http://doc.qt.io/qt-5.5/qgraphicsrectitem.html
        if yes, it has
        http://doc.qt.io/qt-5.5/qgraphicsrectitem.html#setRect

        Im not aware how you can have a QRectF in a scene. :)

        mandruk1331 1 Reply Last reply Reply Quote 0
        • mandruk1331
          mandruk1331 @mrjj last edited by

          @mrjj no no, I want to create a QRectF object in the scene and then move it around, smth like QRectF g; g.translate, but the translae does not work for me in thist situation

          Mandruk1331

          1 Reply Last reply Reply Quote 0
          • ?
            A Former User last edited by

            Hi! What type of scene are we talking about? QGraphicsScene?

            mandruk1331 1 Reply Last reply Reply Quote 1
            • mandruk1331
              mandruk1331 @Guest last edited by

              @Wieland yes

              Mandruk1331

              1 Reply Last reply Reply Quote 0
              • ?
                A Former User last edited by A Former User

                Ok. Then you can't add a QRectF to this scene. You can only add objects to the scene that are derived from QGraphicsItem. So, if you want to have a rectangle on the scene it has to be a QGraphicsRectItem. There are 3 options to add such a rectangle to the scene:

                • void QGraphicsScene::addItem(QGraphicsItem * item)

                • QGraphicsRectItem * QGraphicsScene::addRect(const QRectF & rect, const QPen & pen = QPen(), const QBrush & brush = QBrush())

                • QGraphicsRectItem * QGraphicsScene::addRect(qreal x, qreal y, qreal w, qreal h, const QPen & pen = QPen(), const QBrush & brush = QBrush())

                mandruk1331 1 Reply Last reply Reply Quote 1
                • mandruk1331
                  mandruk1331 @Guest last edited by

                  @Wieland and is there is smth like an update rect function? I think that I can make an Update func by removing the item changing it parameters adn adding a new one, but that's quite newbie( I think), is there's another way?

                  Mandruk1331

                  1 Reply Last reply Reply Quote 0
                  • ?
                    A Former User last edited by

                    Yes, there is such a function. You already mentioned it ;-)
                    void QGraphicsItem::setPos(const QPointF & pos)

                    mandruk1331 1 Reply Last reply Reply Quote 0
                    • mandruk1331
                      mandruk1331 @Guest last edited by mandruk1331

                      @Wieland Where I can save the position of this rectangle, because the reurn type in scene and I can't save in the scene Vector
                      scene->addRect(50,0,20,100,Pen,darkMagentaBrush);

                      Found it in the doc.
                      QRectF is the answer;

                      Mandruk1331

                      1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User last edited by

                        Glad you solved it! :-)

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post