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. QT, repaint line that doesn't have boundingRect()

QT, repaint line that doesn't have boundingRect()

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt4python2boundingrectqgraphicssceneshape
2 Posts 2 Posters 1.0k 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.
  • H Offline
    H Offline
    helloworld12345
    wrote on last edited by
    #1

    0_1513739237721_Untitled.png
    There are 3 items in the picture above.

    1. Yellow Rect : QAbstractGraphicsShapeItem
    2. Yellow Point : QAbstractGraphicsShapeItem
    3. Two white lines : just two lines connecting Yellow Rect and Yellow Point

    Yellow Rect and Yellow Point are QAbstractGraphicsShapeItem which has boundingRect() and shape() functions that can detect the location of Rect and Point, so it's working good when I move these two items.

    The two white lines are simply two lines connecting the Rect and Point, when I move point or rect, the lines are supposed to move immediately so it keeps the connections between Rect and Point. However, since two white lines are not in the boundRect area of Yellow Rect and Yellow Point, the two while lines won't update immediately.

    There are two solutions below here, but not ideal, I am looking for better solution.

    1. paint the whole picture whenever Rect and Point moves, two white lines will also re-paint. But I don't want to re-paint the whole picture which contains many other graphics, which is time consuming and not smart.

    2. add the area of two white lines to the BoundingRect() or Shape() of either Yellow Rect or Yellow Point, then two white lines will re-paint immediately since it's part of Rect or Point. But not good, if I drag two white lines, Rect or Point will also be selected and dragged, which is not what I need. The two white lines should never be selected, it's sole purpose is to visually connect Yellow Rect and Yellow Point.

    Any better solutions? Thanks in advance.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I just keep a pointer to the "white lines" and adjust if i move yellow.

      class ColorItem : public QGraphicsItem {
      ..
        ConnectorLine* line = nullptr;
      ..
      protected:
        QVariant itemChange(GraphicsItemChange change, const QVariant& value) override {
      
          if (change == ItemPositionChange && scene()) {
            if (line) {
              line->adjust();
            }
      
          }
          return QGraphicsItem::itemChange(change, value);
        }
      private:
        QColor color;
      
      };
      
      
      

      line->Adjust() alters its endpoints. You could just adjust it directly here.

      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