Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Connect CustomObjects with a line between them
Hi, I'm very new to GUI programming. I'm scratching my ahead around this one:
I want a button so that when its pressed gets the next two clicked objects and draw a line between them.
What I don't know:
- Once the button is pressed getting the two clicked objects
- Drawing a Line and Connecting both objects so that if I move one the line will follow it (stretch, contract, break, etc)
Basically, like an ER Diagram, since the objects here are all rectangles.
Sounds like an "edit mode" button. Can you give a bit more details about what you are currently using ? Is it the graphics view framework ? Widgets ? QtQuick ?
@SGaist Sure, thanks for the reply! I'm creating a mainwindow using QGraphicsView to display movable objects which are custom QGraphicsItems. I want the user to be able to freely connect/disconnect these objects similar to the way an ER Diagram is made using MySQL workbench.
You should take a look at the Elastic Nodes example.
As for the click handling you might want to use an event filter that will act in "edit mode" to catch the two next click when the mode is activated.
@SGaist Thanks! That's precisely what I needed regarding the connected objects. As for the "edit mode" I'll have to read a bit more into it since I'm new to UI developing and Qt. Any links you can recommend me would be of great help.
Nothing special about it. It's a bit like the "text/preview" you have with the markdown editor on e.g. Gitlab. In this case you have your application running "normally" and when you click on some button/menu item, you activate some additional layer that will handle the next two items you click.
Just as a note
This sample also allows connected objects
and can provide good basic if you make anything like a diagram editor.