B
B
blackfishsql002020-02-23 12:02:06
Qt
blackfishsql00, 2020-02-23 12:02:06

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 QGraphicsItemclass Edge : public QGraphicsItem

class NodeСircle : public Nodeclass NodeSquare : public NodeNodeСircle <--> NodeСircleNodeSquare <--> NodeSquareNodeSquare <--> NodeСircleEdge

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 Nodeclass NodeSquare : public Node

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
#, 2020-02-23
@mindtester

first separate logic and display in your head

B
blackfishsql00, 2020-02-24
@blackfishsql00

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 question

Ask a Question

731 491 924 answers to any question