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. [SOLVED]Move QRectF

[SOLVED]Move QRectF

Scheduled Pinned Locked Moved Solved General and Desktop
qrectfscene
10 Posts 3 Posters 3.1k 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.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by mandruk1331
    #1

    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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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. :)

      mandruk1331M 1 Reply Last reply
      0
      • mrjjM mrjj

        @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. :)

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on last edited by
        #3

        @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
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

          mandruk1331M 1 Reply Last reply
          1
          • ? A Former User

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

            mandruk1331M Offline
            mandruk1331M Offline
            mandruk1331
            wrote on last edited by
            #5

            @Wieland yes

            Mandruk1331

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by A Former User
              #6

              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())

              mandruk1331M 1 Reply Last reply
              1
              • ? 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())

                mandruk1331M Offline
                mandruk1331M Offline
                mandruk1331
                wrote on last edited by
                #7

                @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
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #8

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

                  mandruk1331M 1 Reply Last reply
                  0
                  • ? A Former User

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

                    mandruk1331M Offline
                    mandruk1331M Offline
                    mandruk1331
                    wrote on last edited by mandruk1331
                    #9

                    @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
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #10

                      Glad you solved it! :-)

                      1 Reply Last reply
                      0

                      • Login

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