Draw lines,arcs at design time then change color on an event at runtime
-
I want to design a diagram consisting of lines and curves (arcs) at design time, preferable in a WYSIWYG tool. Such that, when used in a Qt for Python app, the color of specific graphic items can be changed in response to events. Seems simple but I don't see anything in Qt Design Studio or Qt Creator to allow simple graphical elements to be added to a qml or similar file.
-
I want to design a diagram consisting of lines and curves (arcs) at design time, preferable in a WYSIWYG tool. Such that, when used in a Qt for Python app, the color of specific graphic items can be changed in response to events. Seems simple but I don't see anything in Qt Design Studio or Qt Creator to allow simple graphical elements to be added to a qml or similar file.
-
The diagram is of a model railway layout divided into sections and the color change shows when the sections are occupied.
Something like :-
But this uses QtQuick.Studio.Components which are not found in QtCreator for Python. (There does not seem to be a simple LIne element either, I used the border item.) -
You have to select the item that you want to edit the property, then in the property editor you search the property that you want.
In your case you select the arc, and you search it's color.
Then you got a little icon in shape of an hexagon, as shown in the pictureyou click that icon then "set binding" and a new dialog opens.
So for the remainder of this part I will assume that each track section item has a property returning the state of the corresponding section.
in the dialog you simply would simply write
section.occupied ? "colorIfOccupied" : "colorIfFree"
Of course yours to adapt this to the reality of your data structure.
-
The diagram is of a model railway layout divided into sections and the color change shows when the sections are occupied.
Something like :-
But this uses QtQuick.Studio.Components which are not found in QtCreator for Python. (There does not seem to be a simple LIne element either, I used the border item.) -
I've been trying QGraphicsView. A few problems. 1. There is no QGraphicsArcItem, the ellipse item can be told to create partial ellipses but I haven't found a way to make it create arcs - it creates pie pieces. 2. Using the QGraphicsPathItem sort of works but I haven't found a way to stop it adding a line to the start of the arc. e.g.:-
(the arcMoveTo doesn't work either - it picks the wrong end of the arc to move to) -
-
Ok. I'm now trying to use QtQuick2. But different problems. Mainly that the component QtQuick.Studio.Components is not found on my Raspberry Pi instance of Qt. On my Windows PC I can make it work by following suggestions in
https://stackoverflow.com/questions/65664346/qml-module-not-found-qtquick-studio-components-1-0 , which involves copying a folder from the QtDesignerStudio install across to the QtCreator install.
But that does not work on the RPi - can't see any equivalent directory/folder with the required files.
What I want to do now is use the SVG Path Item widget from QtQuick.Studio.Components to create all the shapes (arcs, lines etc.). -
I've been trying QGraphicsView. A few problems. 1. There is no QGraphicsArcItem, the ellipse item can be told to create partial ellipses but I haven't found a way to make it create arcs - it creates pie pieces. 2. Using the QGraphicsPathItem sort of works but I haven't found a way to stop it adding a line to the start of the arc. e.g.:-
(the arcMoveTo doesn't work either - it picks the wrong end of the arc to move to)@JimLomax said in Draw lines,arcs at design time then change color on an event at runtime:
There is no QGraphicsArcItem, the ellipse item can be told to create partial ellipses but I haven't found a way to make it create arcs
Make your own "arc"-item (one for each kind of any piece of your track... 30° corner, 45° corner, straight, etc. etc.)?!
You can rotate and flip them like Tetris blocks afterwards...That's why you subclass
QGraphicItem
... to customize your items and do whatever you like.@ankou29666 said in Draw lines,arcs at design time then change color on an event at runtime:
https://www.qt.io/blog/2017/01/19/should-you-be-using-qgraphicsview
There is nothing wrong with using
QGraphicsView
...
when creating Desktop apps you don't necessarily have to use QML/QtQuick -
I never said there's anything wrong with it. I just find it particularly interesting to know the role it played in Qt's history : the underlying of QtQuick v1 ... in Qt4.7 and 4.8 !!! and what it likely could become in the future.
I personnaly wouldn't recommend (and i'm probably not the only one) the use for a new design of a framework that was stated already 8 years ago as no future. From that article, I see no relevant feature of QGraphicsView that is not available in QML and that OP might be interested in.
-
I've been trying QGraphicsView. A few problems. 1. There is no QGraphicsArcItem, the ellipse item can be told to create partial ellipses but I haven't found a way to make it create arcs - it creates pie pieces. 2. Using the QGraphicsPathItem sort of works but I haven't found a way to stop it adding a line to the start of the arc. e.g.:-
(the arcMoveTo doesn't work either - it picks the wrong end of the arc to move to)@JimLomax said in Draw lines,arcs at design time then change color on an event at runtime:
- There is no QGraphicsArcItem, the ellipse item can be told to create partial ellipses but I haven't found a way to make it create arcs - it creates pie pieces. 2. Using the QGraphicsPathItem sort of works but I haven't found a way to stop it adding a line to the start of the arc
I don't have anything to say about QML vs widgets as I only use the latter. But if you are still interested in how to draw an arc on a
QGraphicsScene
without the pie/line QT QGraphicsScene Drawing Arc shows how to do that.