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. Will paint(), redraw everything from scene or will redraw only updated items in Qt?

Will paint(), redraw everything from scene or will redraw only updated items in Qt?

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 4 Posters 1.7k Views 2 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.
  • T Offline
    T Offline
    tushu
    wrote on last edited by tushu
    #1

    I have QGraphicsView which contains many QGraphicsItem such as Rectangle, polylines. I have overriden paint() method. I am drawing QGraphicsItem using boost-graph. While drawing items, I am storing boost-graph pointer on every QGraphicsItem.
    Now I am right clicking on some rectangle from scene and trying to hide it. While hiding it, I am trying to hide lines connected to it also. For that, I am taking boost-graph pointer stored at every item and iterating through it.
    In boost graph, there is a flag isVisible, through setting-resetting it, I am hidding-unhidding that item.

    myView.cpp

    void myClass:: DrawRect()
    {
         while(true)
          {
             // iterating thorugh boost-graph and finding co-ordinates
             myRect* _rect = new myRect(rect co-ordinates);
             _rect->setBrush(Qt::yellow);
             _rect->setPtr(boost-graph pointer);
             _scene->addItem(static_cast<QGraphicsRectItem*>(_rect));
         }
         
               
         
         void myView::HideSelectedRectangle() // after choosing hide from right mouse click, control comes here
         {
             foreach(QGraphicsItem* currentItem, _scene->selectedItems())
             {
                 myRect* rItem = qgraphicsitem_cast<myRect*>(currentItem);
                 if(rItem)
                 {
                      VertexDescriptor vPtr = rItem->getBoostPtr();  // getting boost-graph ptr
                      // logic for making it hide
                      // Question is how paint() will know about this QGraphicsItem that it is hidden? 
         
                 };
             }    
         }
    

    myRect.cpp

    ```
    
    void myRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
        {
            auto copied_option = *option;
            copied_option.state &= ~QStyle::State_Selected;
            auto selected = option->state & QStyle::State_Selected;
            QGraphicsRectItem::paint(painter, &copied_option, widget);
            if(selected)
            {
                painter->save();
                painter->setBrush(Qt::NoBrush);
                painter->setPen(QPen(option->palette.windowText(), 0, Qt::SolidLine));
                painter->drawPath(shape());
                painter->restore();
            }
        }
    
    void myRect::setPtr(VertexDescriptor vIter)
    {
        this->boostPtr = vIter;
    }
    
    VertexDescriptor myRect::getPtr()
    {
        return boostPtr;
    }
    
    

    myRect.h

    class myRect: public QGraphicsRectItem
    {
    public:
        explicit myRect();
        explicit myRect(QRectF &rectPoints,QGraphicsItem *parent = nullptr)
            : QGraphicsRectItem(rectPoints,parent){}
      void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
      void setPtr(VertexDescriptor);
      VertexDescriptor getPtr();
      VertexDescriptor boostPtr;
    }
    

    Now assume I have made _isVisible = false (which is in boost-graph) for rectangle and some connected lines. And now I want to redraw view using paint(). And expecting, paint() should not draw those rectangle and lines which are marked as not visible.

    Is paint() redraw every QGraphicsItem from view or it will redraw only those were updated ?
    How paint() will know, which shape should it draw and its co-ordinates ?
    Is it possible in my paint(), by checking QGraphicsItem's flag (isVisible) I can guide paint() which items to redraw and which not to redraw ?
    T 1 Reply Last reply
    0
    • T tushu

      I have QGraphicsView which contains many QGraphicsItem such as Rectangle, polylines. I have overriden paint() method. I am drawing QGraphicsItem using boost-graph. While drawing items, I am storing boost-graph pointer on every QGraphicsItem.
      Now I am right clicking on some rectangle from scene and trying to hide it. While hiding it, I am trying to hide lines connected to it also. For that, I am taking boost-graph pointer stored at every item and iterating through it.
      In boost graph, there is a flag isVisible, through setting-resetting it, I am hidding-unhidding that item.

      myView.cpp

      void myClass:: DrawRect()
      {
           while(true)
            {
               // iterating thorugh boost-graph and finding co-ordinates
               myRect* _rect = new myRect(rect co-ordinates);
               _rect->setBrush(Qt::yellow);
               _rect->setPtr(boost-graph pointer);
               _scene->addItem(static_cast<QGraphicsRectItem*>(_rect));
           }
           
                 
           
           void myView::HideSelectedRectangle() // after choosing hide from right mouse click, control comes here
           {
               foreach(QGraphicsItem* currentItem, _scene->selectedItems())
               {
                   myRect* rItem = qgraphicsitem_cast<myRect*>(currentItem);
                   if(rItem)
                   {
                        VertexDescriptor vPtr = rItem->getBoostPtr();  // getting boost-graph ptr
                        // logic for making it hide
                        // Question is how paint() will know about this QGraphicsItem that it is hidden? 
           
                   };
               }    
           }
      

      myRect.cpp

      ```
      
      void myRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
          {
              auto copied_option = *option;
              copied_option.state &= ~QStyle::State_Selected;
              auto selected = option->state & QStyle::State_Selected;
              QGraphicsRectItem::paint(painter, &copied_option, widget);
              if(selected)
              {
                  painter->save();
                  painter->setBrush(Qt::NoBrush);
                  painter->setPen(QPen(option->palette.windowText(), 0, Qt::SolidLine));
                  painter->drawPath(shape());
                  painter->restore();
              }
          }
      
      void myRect::setPtr(VertexDescriptor vIter)
      {
          this->boostPtr = vIter;
      }
      
      VertexDescriptor myRect::getPtr()
      {
          return boostPtr;
      }
      
      

      myRect.h

      class myRect: public QGraphicsRectItem
      {
      public:
          explicit myRect();
          explicit myRect(QRectF &rectPoints,QGraphicsItem *parent = nullptr)
              : QGraphicsRectItem(rectPoints,parent){}
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
        void setPtr(VertexDescriptor);
        VertexDescriptor getPtr();
        VertexDescriptor boostPtr;
      }
      

      Now assume I have made _isVisible = false (which is in boost-graph) for rectangle and some connected lines. And now I want to redraw view using paint(). And expecting, paint() should not draw those rectangle and lines which are marked as not visible.

      Is paint() redraw every QGraphicsItem from view or it will redraw only those were updated ?
      How paint() will know, which shape should it draw and its co-ordinates ?
      Is it possible in my paint(), by checking QGraphicsItem's flag (isVisible) I can guide paint() which items to redraw and which not to redraw ?
      T Offline
      T Offline
      tushu
      wrote on last edited by tushu
      #2

      @SGaist , @JonB Please help.
      If you are confused, then I tell you in short, what I want ?
      In my paint(), I want QGraphicsItem which are updated. Once I get those items, ( I have kept boost-graph pointer on each item) I can access boost-graph flag isVisible, and change it to false. And tell paint() method please draw it. paint() will see that flag and will not draw it. And I successfully hide that item. Is it possible ?

      JonBJ 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Why not make use of the setVisible method of the base class ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        T 1 Reply Last reply
        0
        • T tushu

          @SGaist , @JonB Please help.
          If you are confused, then I tell you in short, what I want ?
          In my paint(), I want QGraphicsItem which are updated. Once I get those items, ( I have kept boost-graph pointer on each item) I can access boost-graph flag isVisible, and change it to false. And tell paint() method please draw it. paint() will see that flag and will not draw it. And I successfully hide that item. Is it possible ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @tushu
          I have never used (or heard of) "boost graph". I can guess you are doing some sort of "shadowing" of graphics objects which it holds.

          The paint() you show is to (re-)paint a myRect. So it does not "redraw every QGraphicsItem from view", it is called when a myRect instance needs to be (re-)painted. It is not paint()'s job to "redraw only those were updated". The framework notes which GraphicsItems are updated and need repainting, and only calls paint() on those marked changed/dirty. paint() is being called on a myRect, so that is how it "know, which shape should it draw and its co-ordinates".

          If you are saying boost graph has some "is visible" property on its objects, then presumably you should shadow that on your corresponding QGraphicsItem's visible property.

          It may sound like you are trying to do too much in your paint() method. You are supposed to do operations on the QGraphicsItems themselves, they just call paint() when you have changed something.

          T 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            Why not make use of the setVisible method of the base class ?

            T Offline
            T Offline
            tushu
            wrote on last edited by tushu
            #5

            @SGaist It will increse time complexity. I want to hide lines which are connected to rectangle. If those lines are connected to some other items then that also I need to hide. So I was told to use this approach. Simplly put flag isVisible = false and let do work to paint()

            JonBJ 1 Reply Last reply
            0
            • T tushu

              @SGaist It will increse time complexity. I want to hide lines which are connected to rectangle. If those lines are connected to some other items then that also I need to hide. So I was told to use this approach. Simplly put flag isVisible = false and let do work to paint()

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @tushu
              These "lines which are connected to rectangle": are the lines represented by QGraphicsItems? (Presumably just like the rectangle is.) If so you will want to set their visible properties correspondingly, not just do something in paint()?

              1 Reply Last reply
              0
              • JonBJ JonB

                @tushu
                I have never used (or heard of) "boost graph". I can guess you are doing some sort of "shadowing" of graphics objects which it holds.

                The paint() you show is to (re-)paint a myRect. So it does not "redraw every QGraphicsItem from view", it is called when a myRect instance needs to be (re-)painted. It is not paint()'s job to "redraw only those were updated". The framework notes which GraphicsItems are updated and need repainting, and only calls paint() on those marked changed/dirty. paint() is being called on a myRect, so that is how it "know, which shape should it draw and its co-ordinates".

                If you are saying boost graph has some "is visible" property on its objects, then presumably you should shadow that on your corresponding QGraphicsItem's visible property.

                It may sound like you are trying to do too much in your paint() method. You are supposed to do operations on the QGraphicsItems themselves, they just call paint() when you have changed something.

                T Offline
                T Offline
                tushu
                wrote on last edited by
                #7

                @JonB Thank you for your reply.
                For lines I have QGraphicsPathItem. But I did not mention in code to avoid confusion.
                But can I get access of updated QGraphicsItem in paint() ?
                I just want, updated item in paint().

                JonBJ 1 Reply Last reply
                0
                • T tushu

                  @JonB Thank you for your reply.
                  For lines I have QGraphicsPathItem. But I did not mention in code to avoid confusion.
                  But can I get access of updated QGraphicsItem in paint() ?
                  I just want, updated item in paint().

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by
                  #8

                  @tushu said in Will paint(), redraw everything from scene or will redraw only updated items in Qt?:

                  But can I get access of updated QGraphicsItem in paint() ?

                  I don't understand. You showed your void myRect::paint(...). So that myRect, this, is the QGraphicsItem being painted.

                  I just want, updated item in paint().

                  You keep saying that. paint() is/should only be called on those QGraphicsItems which have been updated and need redrawing, so far as I know.

                  T 1 Reply Last reply
                  0
                  • JonBJ JonB

                    @tushu said in Will paint(), redraw everything from scene or will redraw only updated items in Qt?:

                    But can I get access of updated QGraphicsItem in paint() ?

                    I don't understand. You showed your void myRect::paint(...). So that myRect, this, is the QGraphicsItem being painted.

                    I just want, updated item in paint().

                    You keep saying that. paint() is/should only be called on those QGraphicsItems which have been updated and need redrawing, so far as I know.

                    T Offline
                    T Offline
                    tushu
                    wrote on last edited by
                    #9

                    @JonB From your post I understood that, paint() gets called only for updated/dirty items.
                    I was said that, if we hide rectangle by boost-graph then, we dont need to hide its text, its connected lines, their names. It will be hidden automatically. That's why I need updated item like this, so that I can get rItem's boost pointer, make it not visible and then paint() will see it is not visible , so wont draw it. Is this possible ?

                    if(rItem)
                        VertexDescriptor vPtr = rItem->getBoostPtr();
                    
                    
                    JonBJ 1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      Asperamanca
                      wrote on last edited by
                      #10

                      You need to call setVisible(false) or hide() at some point on each QGraphicsItem that you want hidden. The GraphicsView engine needs to know about it, otherwise you'll get funny effects, or just plain code that doesn't work.

                      Not knowing boost graph, I do hope they allow some way to call functions when a graph node's state changes. If this is the case, you can forward the visibility information of each graph node to it's corresponding QGraphicsItem.

                      The paint() function is for painting. It's not intended as a place to execute logic or change state. Sometimes that may be necessary, but mostly, it causes grief and bugs.

                      1 Reply Last reply
                      2
                      • T tushu

                        @JonB From your post I understood that, paint() gets called only for updated/dirty items.
                        I was said that, if we hide rectangle by boost-graph then, we dont need to hide its text, its connected lines, their names. It will be hidden automatically. That's why I need updated item like this, so that I can get rItem's boost pointer, make it not visible and then paint() will see it is not visible , so wont draw it. Is this possible ?

                        if(rItem)
                            VertexDescriptor vPtr = rItem->getBoostPtr();
                        
                        
                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #11

                        @tushu said in Will paint(), redraw everything from scene or will redraw only updated items in Qt?:

                        I was said that, if we hide rectangle by boost-graph then, we dont need to hide its text, its connected lines, their names. It will be hidden automatically.

                        If you mean the QGraphicsItems, are those things childItem()s of the rectangle? Then I assume it's visible status would be carried to its children?

                        I don't think trying to deal in myRect::paint() with the painting or visibility of other QGraphicsItems is a good idea/will work.

                        T 1 Reply Last reply
                        0
                        • JonBJ JonB

                          @tushu said in Will paint(), redraw everything from scene or will redraw only updated items in Qt?:

                          I was said that, if we hide rectangle by boost-graph then, we dont need to hide its text, its connected lines, their names. It will be hidden automatically.

                          If you mean the QGraphicsItems, are those things childItem()s of the rectangle? Then I assume it's visible status would be carried to its children?

                          I don't think trying to deal in myRect::paint() with the painting or visibility of other QGraphicsItems is a good idea/will work.

                          T Offline
                          T Offline
                          tushu
                          wrote on last edited by
                          #12

                          @JonB @Asperamanca @SGaist I1.png
                          I want to hide R1. along with R1, I will have to hide L1,L2 and L3 also as they are connected to hidden item. R2 will also get hidden as it is not connected to any items after L1 and L2 gets hidden.
                          But R3 , R4 and L4 won't be hidden.
                          Is this possible with Parent-Child relationship ? ( Means, here if we make R1 as parent and L1,L2 and L3 are children, then if R1 is hidden then its children will be hidden automatically )

                          JonBJ 1 Reply Last reply
                          0
                          • T tushu

                            @JonB @Asperamanca @SGaist I1.png
                            I want to hide R1. along with R1, I will have to hide L1,L2 and L3 also as they are connected to hidden item. R2 will also get hidden as it is not connected to any items after L1 and L2 gets hidden.
                            But R3 , R4 and L4 won't be hidden.
                            Is this possible with Parent-Child relationship ? ( Means, here if we make R1 as parent and L1,L2 and L3 are children, then if R1 is hidden then its children will be hidden automatically )

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by JonB
                            #13

                            @tushu
                            A picture is worth a thousand words! It would have helped if you had shown this from the start!

                            I believe this can be done, but never tried it. Why don't you give it a brief try?!

                            The "wrinkle" here is that clearly all the other child items are outside the bounding rect of the R1 parent rectangle.

                            If you do it by parent-child, I am thinking you would need to expand the parent rect's boundingRect() to include the QGraphicsItem::childrenBoundingRect(). Normally children are supposed to be inside their parent, I don't know if your case is dealt with/works.

                            Alternatively you should look at QGraphicsItemGroup, and in particular read through its Detailed Description. This may be what you need. Since it inherits QGraphicsItem I presume setting the group's visible property applies to all members of the group, but again you need to check.

                            Really at this point you should check the behaviour for what you want.

                            T 1 Reply Last reply
                            0
                            • JonBJ JonB

                              @tushu
                              A picture is worth a thousand words! It would have helped if you had shown this from the start!

                              I believe this can be done, but never tried it. Why don't you give it a brief try?!

                              The "wrinkle" here is that clearly all the other child items are outside the bounding rect of the R1 parent rectangle.

                              If you do it by parent-child, I am thinking you would need to expand the parent rect's boundingRect() to include the QGraphicsItem::childrenBoundingRect(). Normally children are supposed to be inside their parent, I don't know if your case is dealt with/works.

                              Alternatively you should look at QGraphicsItemGroup, and in particular read through its Detailed Description. This may be what you need. Since it inherits QGraphicsItem I presume setting the group's visible property applies to all members of the group, but again you need to check.

                              Really at this point you should check the behaviour for what you want.

                              T Offline
                              T Offline
                              tushu
                              wrote on last edited by tushu
                              #14

                              @JonB I am being asked about my issues status. So time being I am keeping aside parent-child way of implementation. I will try it on my local machine.
                              Now imagine, in boost-graph, I have created R1 as one vertex. Lines are also treated as vertex. So R1 is connected with 3 vertices , L1,L2 and L3. L2 vertex is connected to R2 vertex etc.....
                              I have R1 vertex and I have set its _isVisible as false. Through R1 I have iterated to L1, L2 and L3 and made it's visibility as false.
                              Now the question is , how to tell paint() that R1,L1,L2 and L3 are updated and draw them again.
                              There, before drawing I will check flag _isVisible and respectively draw it.
                              How paint() will get QGraphicsItem (R1) ( through R1 I can jump to boost-ptr pointer and then flag and then draw )
                              I want that QGraphicsItem (R1) in paint(). Is this possible ?

                              JonBJ 1 Reply Last reply
                              0
                              • T tushu

                                @JonB I am being asked about my issues status. So time being I am keeping aside parent-child way of implementation. I will try it on my local machine.
                                Now imagine, in boost-graph, I have created R1 as one vertex. Lines are also treated as vertex. So R1 is connected with 3 vertices , L1,L2 and L3. L2 vertex is connected to R2 vertex etc.....
                                I have R1 vertex and I have set its _isVisible as false. Through R1 I have iterated to L1, L2 and L3 and made it's visibility as false.
                                Now the question is , how to tell paint() that R1,L1,L2 and L3 are updated and draw them again.
                                There, before drawing I will check flag _isVisible and respectively draw it.
                                How paint() will get QGraphicsItem (R1) ( through R1 I can jump to boost-ptr pointer and then flag and then draw )
                                I want that QGraphicsItem (R1) in paint(). Is this possible ?

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #15

                                @tushu
                                Firstly I really give up at this point. I have no idea how you need to make your Qt items interact with whatever you are doing in your "boost graphics", and I doubt anybody else will either. It really is down to you to try some of this stuff instead of keep asking other people how it might behave, which they won't know.

                                I will say again what has been said by others. paint(), on some graphics object, is really not the place to go try alter e.g. the visibility, or anything else, on other QGraphicsItems. The Qt framework calls paint() on whatever needs updating, according to whatever you have done previously, and its job is just to paint its object. It's not there to play with other objects. For one thing, you have no idea what order objects will have their paint() called; it may have already called paint() on, say, your line items before it calls paint() on your rectangle, for all you know. You have not respected what we have said about this and keep asking about doing stuff to other items in one item's paint(), and that's just not right, keeping asking the same question does not get a different answer. So I'm not going to say that again.

                                I want that QGraphicsItem (R1) in paint(). Is this possible ?

                                Answered this already multiple times. Doesn't stop you keep asking the same thing. You are already in R1s void myRect::paint(...) so you have it in this.

                                Now the question is , how to tell paint() that R1,L1,L2 and L3 are updated and draw them again.

                                You don't tell paint() items have been updated, items which have been updated cause paint() to be called. Changing items' visible value will mark them as updated and cause their paint()s to be called. Do your work on other/all items before paint() is called, whatever causes that to happen on, say, the rectangle do the other items there. Explicitly calling any QGraphicsItem's update() method marks it as "dirty"/needing repainting. Also read https://doc.qt.io/qt-5/qgraphicsitem.html#update.

                                That's me done for the best answers I know on this topic.

                                T 1 Reply Last reply
                                1
                                • JonBJ JonB

                                  @tushu
                                  Firstly I really give up at this point. I have no idea how you need to make your Qt items interact with whatever you are doing in your "boost graphics", and I doubt anybody else will either. It really is down to you to try some of this stuff instead of keep asking other people how it might behave, which they won't know.

                                  I will say again what has been said by others. paint(), on some graphics object, is really not the place to go try alter e.g. the visibility, or anything else, on other QGraphicsItems. The Qt framework calls paint() on whatever needs updating, according to whatever you have done previously, and its job is just to paint its object. It's not there to play with other objects. For one thing, you have no idea what order objects will have their paint() called; it may have already called paint() on, say, your line items before it calls paint() on your rectangle, for all you know. You have not respected what we have said about this and keep asking about doing stuff to other items in one item's paint(), and that's just not right, keeping asking the same question does not get a different answer. So I'm not going to say that again.

                                  I want that QGraphicsItem (R1) in paint(). Is this possible ?

                                  Answered this already multiple times. Doesn't stop you keep asking the same thing. You are already in R1s void myRect::paint(...) so you have it in this.

                                  Now the question is , how to tell paint() that R1,L1,L2 and L3 are updated and draw them again.

                                  You don't tell paint() items have been updated, items which have been updated cause paint() to be called. Changing items' visible value will mark them as updated and cause their paint()s to be called. Do your work on other/all items before paint() is called, whatever causes that to happen on, say, the rectangle do the other items there. Explicitly calling any QGraphicsItem's update() method marks it as "dirty"/needing repainting. Also read https://doc.qt.io/qt-5/qgraphicsitem.html#update.

                                  That's me done for the best answers I know on this topic.

                                  T Offline
                                  T Offline
                                  tushu
                                  wrote on last edited by tushu
                                  #16

                                  @JonB Really really thanks for your help.
                                  Your 1 line cleared all my doubts.
                                  You are already in R1s void myRect::paint(...) so you have it in this.
                                  The above line cleared my doubt regarding paint().
                                  Now I am able to access boost-graph through its pointer put in QGraphicsItem.
                                  I know, I could not explain properly, and at the end, you were a bit angry. Sorry for that. But I can not explain everything because, if size increases, people tend to avoid such questions.
                                  But anyway sorry, next time I will try to explain properly.
                                  Thank you once again. :)

                                  JonBJ 1 Reply Last reply
                                  0
                                  • T tushu

                                    @JonB Really really thanks for your help.
                                    Your 1 line cleared all my doubts.
                                    You are already in R1s void myRect::paint(...) so you have it in this.
                                    The above line cleared my doubt regarding paint().
                                    Now I am able to access boost-graph through its pointer put in QGraphicsItem.
                                    I know, I could not explain properly, and at the end, you were a bit angry. Sorry for that. But I can not explain everything because, if size increases, people tend to avoid such questions.
                                    But anyway sorry, next time I will try to explain properly.
                                    Thank you once again. :)

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by
                                    #17

                                    @tushu said in Will paint(), redraw everything from scene or will redraw only updated items in Qt?:

                                    You are already in R1s void myRect::paint(...) so you have it in this.
                                    The above line cleared my doubt regarding paint().

                                    Not a problem. Explanations can be tricky, especially in non-native languages. But I said that much earlier on in a couple of posts:

                                    paint() is being called on a myRect, so that is how it "know, which shape should it draw and its co-ordinates".

                                    You showed your void myRect::paint(...). So that myRect, this, is the QGraphicsItem being painted.

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      From the looks of it, it seems you should go the other way around. Build a simple structure that describes the elements of your graph and in that structure have a pointer to the matching QGraphicsItem that should be handled by it so that when you need to remove it from the graph, you can call hide on the item as well.

                                      Note that I have not used boost's graph library so it's more of a suggestion based on your input.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      1

                                      • Login

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