Answer the question
In order to leave comments, you need to log in
How to correctly type QGraphicsItem?
I'm trying to draw a graph. I took as a basis the standard example in QT Elastic Nodes Example https://doc.qt.io/qt-5/qtwidgets-graphicsview-elas... and I want to modify it a bit as follows. The example describes a class and a class . Accordingly, all the code is tied to the data of the 2nd class.
I don't understand how to do the following. I want to make my own classes and . Inside these two classes there will be different fields and their own logic for working with data. An edge can be built between any variants of these classes ( , , and vice versa). To build an edge between two objects, it turns out you need to pass a pointer to the base class somehow? I don't understand what the class constructor should look like then ??class Node : public QGraphicsItem
class Edge : public QGraphicsItem
class NodeСircle : public Node
class NodeSquare : public Node
NodeСircle <--> NodeСircle
NodeSquare <--> NodeSquare
NodeSquare <--> NodeСircle
Edge
And the second question. Suppose there is already a drawn graph. I right-click on the element on the scene to call the context menu, let's say I click on and select the item "Convert to square" and so that an element of the class appears in its place . How to implement this functionality correctly? class NodeСircle : public Node
class NodeSquare : public Node
Answer the question
In order to leave comments, you need to log in
Now I have implemented everything using a flag and I store all the data (data of descendant classes) in one class. And every time you have to check this flag. This solution is not very beautiful.... How to do it right!?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question