Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Draw lines,arcs at design time then change color on an event at runtime
Forum Updated to NodeBB v4.3 + New Features

Draw lines,arcs at design time then change color on an event at runtime

Scheduled Pinned Locked Moved Unsolved Qt for Python
11 Posts 4 Posters 771 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JimLomax
    wrote on last edited by
    #1

    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.

    Pl45m4P 1 Reply Last reply
    0
    • J JimLomax

      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.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by
      #2

      @JimLomax

      What about this?


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JimLomax
        wrote on last edited by
        #3

        The diagram is of a model railway layout divided into sections and the color change shows when the sections are occupied.
        Something like :-

        image.png
        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.)

        Pl45m4P 1 Reply Last reply
        0
        • A Offline
          A Offline
          ankou29666
          wrote on last edited by ankou29666
          #4

          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 picture

          Capture d'écran 2024-10-02 220942.png

          you 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.

          1 Reply Last reply
          1
          • J JimLomax

            The diagram is of a model railway layout divided into sections and the color change shows when the sections are occupied.
            Something like :-

            image.png
            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.)

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @JimLomax

            Since it's a bit clearer now what you are thinking of, the Qt Graphics View framework might be worth a try.
            The tracks could be single QGraphicsItems then.

            • https://doc.qt.io/qtforpython-6.5/overviews/graphicsview.html

            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JimLomax
              wrote on last edited by
              #6

              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.:-
              image.png
              (the arcMoveTo doesn't work either - it picks the wrong end of the arc to move to)

              Pl45m4P JonBJ 2 Replies Last reply
              0
              • A Offline
                A Offline
                ankou29666
                wrote on last edited by
                #7

                https://www.qt.io/blog/2017/01/19/should-you-be-using-qgraphicsview

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JimLomax
                  wrote on last edited by
                  #8

                  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.).

                  1 Reply Last reply
                  0
                  • J JimLomax

                    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.:-
                    image.png
                    (the arcMoveTo doesn't work either - it picks the wrong end of the arc to move to)

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #9

                    @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


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      ankou29666
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • J JimLomax

                        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.:-
                        image.png
                        (the arcMoveTo doesn't work either - it picks the wrong end of the arc to move to)

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @JimLomax said in Draw lines,arcs at design time then change color on an event at runtime:

                        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

                        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.

                        1 Reply Last reply
                        1

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved