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 covered by mysterious white space
QtWS25 Last Chance

QGraphicsItem covered by mysterious white space

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 1.6k 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.
  • D Offline
    D Offline
    danifujii
    wrote on last edited by danifujii
    #1

    Hi guys.
    I need your help again! I have a problem drawing some items in a scene. This items are "attributes" composed of a circle and a text line next to it. The problem is, some of these attributes are covered by a mysterious white space when moving them to the right or bottom edge of a QGraphicsScene.
    The weird part is, this only happens when drawing these in a "Relationship" class, but it does not when doing so in a "Entity" class. Weirder still? The drawing is handled by the Attribute itself through a method "addToScene" (the attributes are not QGraphicsItem like the rest of the classes). This method is called by Entity or Relationship to draw them.
    Here is an image of the situation:
    Image link
    As you can see, the circles (which are also drawn by the Attribute class) are not covered, however the text is. I am asking because I find it extremely weird.
    Some example code:

    void RBinaryItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    foreach(Attribute * att, rship->getAttributes()){
            att->addToScene(painter,x,y);
            y += 15;
        }
    }
    

    That is the paint method in Relationship class. The Entity class does the exact same usage.
    Thank you very much. Hope someone has an idea.

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      Hello,
      It looks like some kind of clipping occurs, maybe compare the "attribute" objects' painting method, as it seems that the topmost circle (and text) are rendered properly?
      Additional code would be helpful, if you'd be willing to share it.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      D 1 Reply Last reply
      0
      • kshegunovK kshegunov

        Hello,
        It looks like some kind of clipping occurs, maybe compare the "attribute" objects' painting method, as it seems that the topmost circle (and text) are rendered properly?
        Additional code would be helpful, if you'd be willing to share it.

        Kind regards.

        D Offline
        D Offline
        danifujii
        wrote on last edited by
        #3

        @kshegunov Well, here i show you the important part of the addToScene method in Attribute class.

        int Atttribute::addToScene(QPainter *painter, int x, int y){
        painter->drawText(QRectF(QPoint(x+30, y+5),QPointF(200, 200)), this->getName());
        painter->drawEllipse(x+20, y+9, 8, 8);
        }
        

        Hope this helps. Attribute class does not inherit QGraphicsItem, I received the code and will try, as long as I can, to keep it that way.
        Thanks!

        kshegunovK 1 Reply Last reply
        0
        • D danifujii

          @kshegunov Well, here i show you the important part of the addToScene method in Attribute class.

          int Atttribute::addToScene(QPainter *painter, int x, int y){
          painter->drawText(QRectF(QPoint(x+30, y+5),QPointF(200, 200)), this->getName());
          painter->drawEllipse(x+20, y+9, 8, 8);
          }
          

          Hope this helps. Attribute class does not inherit QGraphicsItem, I received the code and will try, as long as I can, to keep it that way.
          Thanks!

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @danifujii
          Hello,
          Isn't QRectF(QPoint(x+30, y+5),QPointF(200, 200)) a bit suspicious? You set the top-left point relative to x and y, but put the bottom-right as fixed coordinates? Maybe try QPoint(x + 200, y + 200)? Aside from that it looks okay.

          Read and abide by the Qt Code of Conduct

          D 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @danifujii
            Hello,
            Isn't QRectF(QPoint(x+30, y+5),QPointF(200, 200)) a bit suspicious? You set the top-left point relative to x and y, but put the bottom-right as fixed coordinates? Maybe try QPoint(x + 200, y + 200)? Aside from that it looks okay.

            D Offline
            D Offline
            danifujii
            wrote on last edited by
            #5

            @kshegunov Right? I don't get why it would happen when used within a certain class and not with others.

            kshegunovK 1 Reply Last reply
            0
            • D danifujii

              @kshegunov Right? I don't get why it would happen when used within a certain class and not with others.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @danifujii
              I don't know, it does seem fine. Is it possible that something else (another item) is wanting to draw on top of this one and is erasing the background, although this seems far fetched?

              Read and abide by the Qt Code of Conduct

              D 1 Reply Last reply
              0
              • kshegunovK kshegunov

                @danifujii
                I don't know, it does seem fine. Is it possible that something else (another item) is wanting to draw on top of this one and is erasing the background, although this seems far fetched?

                D Offline
                D Offline
                danifujii
                wrote on last edited by danifujii
                #7

                @kshegunov I wouldn't think so as the only things that are added are the squares and rhombus items.

                SOLVED: It was what you said, the painting was wrong. It should have been x+200, y+200. That was code I received, that is why I didn't inspect it too much.
                Thank you!

                kshegunovK 1 Reply Last reply
                0
                • D danifujii

                  @kshegunov I wouldn't think so as the only things that are added are the squares and rhombus items.

                  SOLVED: It was what you said, the painting was wrong. It should have been x+200, y+200. That was code I received, that is why I didn't inspect it too much.
                  Thank you!

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @danifujii
                  You're welcome.
                  Kind regards.

                  Read and abide by the Qt Code of Conduct

                  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