Fading Effect for segmented line (QGraphicsLineItem)

32 views Asked by At

I am drawing using QgraphicsLineItem such that after reaching certain length, it should give me fading effect for the line. So, the basic way I had used is appending its objects to a list and later setting its opacity which would give a fading type of effect. But the problem I am facing here is it is disappearing, but the points which connect a line gets overlapped.

Segmented Line Image

Below is the code Snippet:

   # Inherited Plotwidget class 
 
   def drawLine1(self,x,y,z):
            # Here x,y are coordinates and z if force for finger 1
            item = pg.QtWidgets.QGraphicsLineItem()
            item.setPen(pg.mkPen(width= z+ ModeOne.pen_wid_1, color = ModeOne.color_1))
            # For drawing one point

               if x[-2] == x [-1]:
                    x[-2] = x[-1] - 1
                    y[-2] = y[-1] - 1

               item.setLine(x[-2],y[-2],x[-1],y[-1])

  
        self.addItem(item)
        self.rectdata_fir.append(item)
    self.disappear_item(self.rectdata_fir)

    def disappear_item(self, item_list):
        if len(item_list)>50:
            item_list[10].setOpacity(0.10)
            item_list[9].setOpacity(0.09)
            item_list[8].setOpacity(0.08)
            item_list[7].setOpacity(0.07)
            item_list[6].setOpacity(0.07)
            item_list[5].setOpacity(0.05)
            item_list[4].setOpacity(0.04)
            item_list[3].setOpacity(0.03)
            item_list[2].setOpacity(0.02)
            item_list[1].setOpacity(0.01)
            self.removeItem(item_list.pop(0))
        

So, initially have tried grouping that items into QGraphicsItemGroup and then set its opacity effect to 0.1. Alternatively, I had tried to set GraphicsEffect as opacity effect for each item.

0

There are 0 answers