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.
  • M Offline
    M Offline
    mandruk1331
    wrote on 27 Jan 2016, 21:19 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 27 Jan 2016, 21:36 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. :)

      M 1 Reply Last reply 27 Jan 2016, 21:43
      0
      • M mrjj
        27 Jan 2016, 21:36

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

        M Offline
        M Offline
        mandruk1331
        wrote on 27 Jan 2016, 21:43 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 27 Jan 2016, 21:48 last edited by
          #4

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

          M 1 Reply Last reply 27 Jan 2016, 21:52
          1
          • ? A Former User
            27 Jan 2016, 21:48

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

            M Offline
            M Offline
            mandruk1331
            wrote on 27 Jan 2016, 21:52 last edited by
            #5

            @Wieland yes

            Mandruk1331

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on 27 Jan 2016, 21:58 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())

              M 1 Reply Last reply 27 Jan 2016, 22:08
              1
              • ? A Former User
                27 Jan 2016, 21:58

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

                M Offline
                M Offline
                mandruk1331
                wrote on 27 Jan 2016, 22:08 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 27 Jan 2016, 22:11 last edited by
                  #8

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

                  M 1 Reply Last reply 27 Jan 2016, 22:21
                  0
                  • ? A Former User
                    27 Jan 2016, 22:11

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

                    M Offline
                    M Offline
                    mandruk1331
                    wrote on 27 Jan 2016, 22:21 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 27 Jan 2016, 22:32 last edited by
                      #10

                      Glad you solved it! :-)

                      1 Reply Last reply
                      0

                      5/10

                      27 Jan 2016, 21:52

                      • Login

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