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. QGraphicsItem: any convenience function like setRect()?
Forum Updated to NodeBB v4.3 + New Features

QGraphicsItem: any convenience function like setRect()?

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.0k 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.
  • C Offline
    C Offline
    Code_ReaQtor
    wrote on last edited by
    #1

    Hi!

    I wanted to resize different types of QGraphicsItem without subclassing them.

    It seems like ONLY QGraphicsRectItem and QGraphicsEllipseItem have the member "setRect()" to resize them from the outside.

    Are there any ways I can achieve this?

    Please visit my open-source projects at https://github.com/Code-ReaQtor.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      utcenter
      wrote on last edited by
      #2

      "void QGraphicsItem::setScale":http://doc.qt.digia.com/qt/qgraphicsitem.html#setScale can be used to resize/rescale a QGraphicsItem

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Code_ReaQtor
        wrote on last edited by
        #3

        [quote author="utcenter" date="1358744881"]"void QGraphicsItem::setScale":http://doc.qt.digia.com/qt/qgraphicsitem.html#setScale can be used to resize/rescale a QGraphicsItem[/quote]

        Sorry, but that only have 1 parameter. I need 2 dimensions - length and width... or a QRectF parameter. Any other options?

        Please visit my open-source projects at https://github.com/Code-ReaQtor.

        1 Reply Last reply
        0
        • U Offline
          U Offline
          utcenter
          wrote on last edited by
          #4

          The scale method is designed to proportionally scale the size of the item, a scale of 1 is the normal size, a scale of 2 the item is twice as big, a scale of 0.5 the item is twice as small.

          If you want to use non-proportional scaling, you have to use a transform matrix, in which you can incorporate the custom "length and width" - however doing disproportional transformation may distort and make your item ugly looking.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Code_ReaQtor
            wrote on last edited by
            #5

            Actually, I was able to use QTransform, and distortion was my big problem. It even distort the childItems, which is not my goal. My only goal is to resize the parent item while maintaining the sizes of the child items. Using scale and QTransform would be a bad idea! AFAIK

            QGraphicsRectItem::setRect() and QGraphicsEllipseItem::setRect() makes my goal achievable but for other QGraphicsItem it fails.

            Please visit my open-source projects at https://github.com/Code-ReaQtor.

            1 Reply Last reply
            0
            • U Offline
              U Offline
              utcenter
              wrote on last edited by
              #6

              Well, it figures, rect and ellipse item use a qrect for drawing. If you go for that approach and incorporate a QRect inside of your item and center your custom painting around it, you can add the setRect method and only alter the dimensions of the parent item just as you want to.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Code_ReaQtor
                wrote on last edited by
                #7

                I guess subclassing the QGraphicsItems (pixmap, text, etc.) would be a better choice then.

                or can we ask for a feature request for this?

                Please visit my open-source projects at https://github.com/Code-ReaQtor.

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  utcenter
                  wrote on last edited by
                  #8

                  QGraphicsItem is a generic class, created for the purpose of being subclassed, so I would go with that. The type of functionality you want is not standard to QGraphicsItem's typical usage scenario, so I doubt a feature request will do any good. Just subclass, add a QRect member and use it to dimension the paint event, add the setRect() method and you have the functionality you want.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    steno
                    wrote on last edited by
                    #9

                    QGraphicsWidget doesn't have a setRect, but it does have a setGeometry, which is the same thing. That might be an option worth looking into.

                    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