title: How to open context menu for an object that is empty, but has a size?
body: <p>I am creating a GUI for a dependency graphing software... And am not able to figure out how to get a context menu to open for my lines.</p>
  <p>What I want to do, right click on/near a MyLine widget and open a context menu... What is happening right clicks are not detected.</p>
  <p>It is currently not detecting right clicks on the line widgets location to open a context menu (Purpose of this is to allow the user to delete/edit lines by right clicking on them).</p>
  <p>What am I doing wrong here?</p>
  <pre class="lang-py prettyprint-override"><code>
  class MyLine(QWidget):
     def __init__(self, destination: Node, source: Node, parent=None):
        super().__init__(parent)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.showMenu)
        self.destination = destination
        self.source = source
        self.setAutoFillBackground(True)
        p = self.palette()
        p.setColor(self.backgroundRole(), Qt.red)
        self.setPalette(p)
        
     def update_line_size(self):
        origin = self.source.get_line_draw_pos(self.destination.pos())
        destination = self.destination.get_line_draw_pos(self.source.pos())
        leftcornerX = origin.x() if origin.x() &lt; destination.x() else destination.x()
        leftcornerY = origin.y() if origin.y() &lt; destination.y() else destination.y()
        sizeX = abs(origin.x() - destination.x())
        sizeY = abs(origin.y() - destination.y())
        self.setGeometry(leftcornerX, leftcornerY, sizeX, sizeY)
  
     def showMenu(self, _):
        menu = QMenu()
        menu.addAction(&quot;Delete&quot;, self.remove)
        menu.exec_(self.cursor().pos())
  
     def draw(self, painter: QPainter):
        origin = self.source.get_line_draw_pos(self.destination.pos())
        destination = self.destination.get_line_draw_pos(self.source.pos())
        painter.drawLine(origin, destination)
  
        # DRAW ARROW HEAD
        ARROW_SIZE = 10 # Might change
        line_angle = calculate_line_angle(destination, origin)
        draw_arrow_head(destination, painter, line_angle, ARROW_SIZE)
  
     def remove(self):
        self.parent().delete_line(self)
        self.deleteLater()
  </code></pre>
  <p>Edit:
  required types for reproducibility</p>
  <pre><code>class Node(QLabel):
     def __init__(self, text: str, parent=None):
        super().__init__(text, parent)
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self.showMenu)
     
     def get_line_draw_pos(self, other_side: QPoint):
        x = self.pos().x() if other_side.x() &lt; self.pos().x() else (self.pos().x() + self.width())
        y = self.pos().y() if other_side.y() &lt; self.pos().y() else (self.pos().y() + self.height())
        return QPoint(x, y)
     
     def showMenu(self, _):
        pass #purposefully left as a stub
  
  def calculate_line_angle(destination: QPoint, origin: QPoint):
        return math.atan2(destination.y() - origin.y(), destination.x() - origin.x())
  
  def draw_arrow_head(destination: QPoint, painter: QPainter, line_angle: float, arrow_size: float = 10):
        angle1 = math.radians(22.5) + line_angle
        angle2 = math.radians(-22.5) + line_angle
        arrow1 = QPoint( int(destination.x() - arrow_size * math.cos(angle1)), int(destination.y() - arrow_size * math.sin(angle1)))
        arrow2 = QPoint( int(destination.x() - arrow_size * math.cos(angle2)), int(destination.y() - arrow_size * math.sin(angle2)))
        painter.drawLine(destination, arrow1)
        painter.drawLine(destination, arrow2)
  
  
  
  class MainWindow(QWidget):
     def __init__(self):
        super().__init__()
        self.setAcceptDrops(True) # add a drop rule
        self.setMouseTracking(True)
        self.track_origin = None
        self.track_mouse = QPoint(0,0)
        self.lines = []
  
  
     def paintEvent(self, event):
        painter = QPainter(self)
        for line in self.lines:
           line.draw(painter)
           line.update_line_size()
  
     def connectNodes(self, destination: Node, source: Node):
        self.lines.append(MyLine(destination, source))
        self.update()
     
     def delete_line(self, line: MyLine):
        self.lines.remove(line)
        self.update()
  
  app = QApplication([])
  window = MainWindow()
  window.setWindowTitle(&quot;Right Click to remove label&quot;)
  window.setGeometry(100, 100, 400, 200)
  window.move(60,15)
  
  nodes = []
  for index, node_name in enumerate([&quot;hello.txt&quot;, &quot;not_a_villain.txt&quot;, &quot;nope.txt&quot;]):
     node = Node(node_name, window)
     node.move(50 + index*100, 50 + (index%2) * 50)
     nodes.append(node)
  window.connectNodes(nodes[0], nodes[1])
  window.connectNodes(nodes[0], nodes[2])
  window.connectNodes(nodes[1], nodes[2])
  
  
  window.show()
  
  sys.exit(app.exec_())
  </code></pre>