I have an application where I draw 2 custom widgets and then draw a line between them. I want to add a mousePressEvent to the line. What would be the best way to do this? I suppose I could create a QWidget of x pixel thickness and y length and then fill in the whole widget with the colour I want the line to have. Then the QWidget has the mousePressEvent that I can override. This doesn't seem like the most elegant solution and feels more like a workaround. Is there a better way? import sys from PyQt5.QtCore import Qt from PyQt5.QtGui import QPaintEvent, QPainter, QPen, QFont from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QLabel class MyWidget(QWidget): def __init__(self, name, parent): super().__init__(parent) self.setAutoFillBackground(True) self.setFixedSize(300, 100) p = self.palette() p.setColor(self.backgroundRole(), Qt.white) self.setPalette(p) lbl_name = QLabel(name, self) lbl_name.set
A site where you can share knowledge