I am trying to generate an interactive GUI to display dependencies between different systems.
My idea was using PyQt5's QPainter to paint ellipses to represent the systems, and to afterwards use a QLabel in order to add the system's name (and some other information) into the ellipse.
The end result is supposed to look something like this:
However, I seem to misunderstand the way the QMainWindow works. This is my code (without imports) so far:
class Node:
def __init__(self, posx, posy, width, height, caption):
self.posx = posx
self.posy = posy
self.width = width
self.height = height
self.caption = caption
# will get the node information via API from a different system in the future
def get_nodes():
nodes = []
some_node = Node(100, 200, 350, 200, "Central System")
nodes.append(some_node)
return nodes
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.title = "Generic title"
self.top = 200
self.left = 500
self.width = 600
self.height = 400
self.nodes = get_nodes()
# this is where I am attempting to generate a QLabel
for node in self.nodes:
label = QLabel()
label.setText(node.caption)
label.move(node.posx, node.posy)
self.InitWindow()
def InitWindow(self):
self.setWindowIcon(QtGui.QIcon("icon.png"))
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.show()
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(QPen(Qt.black, 5, Qt.SolidLine))
for node in self.nodes:
painter.drawEllipse(node.posx, node.posy, node.width, node.height)
App = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(App.exec())
This results in the following:
After extensive research, I was unable to find a solution to this problem. I have tried moving the for-loop in which I am attempting to generate the QLabels into different parts of the code, but the result remains the same. How can I display the texts inside of the nodes using QLabels? Is there a better way to do it? Or is this even possible with the approach I am following?