跳到內容
  • 版面
  • 最新
  • 標籤
  • 熱門
  • 使用者
  • 群組
  • 搜尋
  • Get Qt Extensions
  • Unsolved
Collapse
品牌標誌
  1. 首頁
  2. General talk
  3. Qt 6
  4. Qt Graphs. Building 2d plot using c++ only.
Forum Updated to NodeBB v4.3 + New Features

Qt Graphs. Building 2d plot using c++ only.

已排程 已置頂 已鎖定 已移動 Unsolved Qt 6
26 貼文 9 Posters 3.9k 瀏覽 4 Watching
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • V 離線
    V 離線
    Vernat
    寫於 最後由 編輯
    #1

    Hello!! I found GraphsView QML Type, but I did not find it c++ class. I found it in the closed part of the library - qgraphsview_p.h
    Why? How to build a 2d plot using C++ classes? QValueAxis and other classes are presented in C++, but not QGraphsView

    Pl45m4P JKSHJ 2 條回覆 最後回覆
    0
    • V Vernat

      Hello!! I found GraphsView QML Type, but I did not find it c++ class. I found it in the closed part of the library - qgraphsview_p.h
      Why? How to build a 2d plot using C++ classes? QValueAxis and other classes are presented in C++, but not QGraphsView

      Pl45m4P 離線
      Pl45m4P 離線
      Pl45m4
      寫於 最後由 Pl45m4 編輯
      #2

      @Vernat

      The former Qt Chart module is now called (and transferred to) Qt Graphs, which includes 2D, 3D plotting and has a C++ as well as a QML interface.

      So for 2D plotting in C++, either :

      • https://doc.qt.io/qt-6/qtgraphs-overview-2d.html

      or the "old":

      • https://doc.qt.io/qt-6/qtcharts-index.html

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

      ~E. W. Dijkstra

      V 1 條回覆 最後回覆
      2
      • Pl45m4P Pl45m4

        @Vernat

        The former Qt Chart module is now called (and transferred to) Qt Graphs, which includes 2D, 3D plotting and has a C++ as well as a QML interface.

        So for 2D plotting in C++, either :

        • https://doc.qt.io/qt-6/qtgraphs-overview-2d.html

        or the "old":

        • https://doc.qt.io/qt-6/qtcharts-index.html
        V 離線
        V 離線
        Vernat
        寫於 最後由 編輯
        #3

        @Pl45m4 Thanks, but you didn't answer my question. How to build 2D plot using c++ only ? I read this documentation and did not find it. Could you show me a small example without the QML code ?

        Pl45m4P 1 條回覆 最後回覆
        0
        • V Vernat

          @Pl45m4 Thanks, but you didn't answer my question. How to build 2D plot using c++ only ? I read this documentation and did not find it. Could you show me a small example without the QML code ?

          Pl45m4P 離線
          Pl45m4P 離線
          Pl45m4
          寫於 最後由 編輯
          #4

          @Vernat

          • https://doc.qt.io/qt-6/qtcharts-examples.html

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

          ~E. W. Dijkstra

          V 1 條回覆 最後回覆
          0
          • Pl45m4P Pl45m4

            @Vernat

            • https://doc.qt.io/qt-6/qtcharts-examples.html
            V 離線
            V 離線
            Vernat
            寫於 最後由 編輯
            #5

            @Pl45m4 They are about using Qt Charts, not about Qt Graphs. I saw https://doc.qt.io/qt-6/graphs-examples-2d.html. They all are about using Qt Graphs from qml side. They use https://doc.qt.io/qt-6/qml-qtgraphs-graphsview.html as the main type for showing a plot. I tried to find its C++ representation and did not find it. That is why I started this topic. Is it possible to build 2d in C++ using Qt Graphs?

            Pl45m4P 1 條回覆 最後回覆
            0
            • V Vernat

              @Pl45m4 They are about using Qt Charts, not about Qt Graphs. I saw https://doc.qt.io/qt-6/graphs-examples-2d.html. They all are about using Qt Graphs from qml side. They use https://doc.qt.io/qt-6/qml-qtgraphs-graphsview.html as the main type for showing a plot. I tried to find its C++ representation and did not find it. That is why I started this topic. Is it possible to build 2d in C++ using Qt Graphs?

              Pl45m4P 離線
              Pl45m4P 離線
              Pl45m4
              寫於 最後由 編輯
              #6

              @Vernat said in Qt Graphs. Building 2d plot using c++ only.:

              Is it possible to build 2d in C++ using Qt Graphs?

              Yes, just look at the module documentation and the C++ classes. That's what I said above.
              But AFAICS there are no Qt Graph C++ Examples yet.
              Most 2D plotting is still in QtCharts. As you can read there, the module is under maintenance.
              Most parts will be moved to the new QtGraphs, which unites QML, C++, 2D and 3D plotting.


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

              ~E. W. Dijkstra

              1 條回覆 最後回覆
              0
              • V 離線
                V 離線
                Vernat
                寫於 最後由 編輯
                #7

                QValueAxis from the charts is not the same as QValueAxis from the graphs, I hope it will be fixed

                Pl45m4P 1 條回覆 最後回覆
                0
                • V Vernat

                  QValueAxis from the charts is not the same as QValueAxis from the graphs, I hope it will be fixed

                  Pl45m4P 離線
                  Pl45m4P 離線
                  Pl45m4
                  寫於 最後由 Pl45m4 編輯
                  #8

                  @Vernat

                  Note: The Qt Charts module is in the maintenance phase. For new projects, consider using the Qt Graphs module. To render 2D charts, QtGraphs uses Qt Quick Shapes, which is a more modern GUI technology compared to the outdated Qt Graphics View Framework used by the Qt Charts module.
                  ( https://doc.qt.io/qt-6/qtcharts-index.html )

                  You said you don't want to deal with QML, but in the future the backend and how Graphs are rendered will be QML even in C++ use cases.

                  @Vernat said in Qt Graphs. Building 2d plot using c++ only.:

                  QValueAxis from the charts is not the same as QValueAxis from the graphs.

                  What is different?
                  Make your own axis?!

                  I hope it will be fixed

                  I don't think they will revert "improvements" to where it was before in QtChart with GraphicsView backend/rendering.


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

                  ~E. W. Dijkstra

                  1 條回覆 最後回覆
                  1
                  • S 離線
                    S 離線
                    SandSnip3r
                    寫於 最後由 編輯
                    #9

                    Damn @Pl45m4, idk why you're being so rude. I found this thread quite helpful because the Qt documentation on this topic is very confusing. The charts page says

                    Note: The Qt Charts module is in the maintenance phase. For new projects, consider using the Qt Graphs module. To render 2D charts, QtGraphs uses Qt Quick Shapes, which is a more modern GUI technology compared to the outdated Qt Graphics View Framework used by the Qt Charts module.

                    Then looking at QtGraphs docs, you just get a bunch of QML source. There's nothing mentioning that 2d charts/graphs are still using the old system.

                    Pl45m4P 1 條回覆 最後回覆
                    0
                    • S SandSnip3r

                      Damn @Pl45m4, idk why you're being so rude. I found this thread quite helpful because the Qt documentation on this topic is very confusing. The charts page says

                      Note: The Qt Charts module is in the maintenance phase. For new projects, consider using the Qt Graphs module. To render 2D charts, QtGraphs uses Qt Quick Shapes, which is a more modern GUI technology compared to the outdated Qt Graphics View Framework used by the Qt Charts module.

                      Then looking at QtGraphs docs, you just get a bunch of QML source. There's nothing mentioning that 2d charts/graphs are still using the old system.

                      Pl45m4P 離線
                      Pl45m4P 離線
                      Pl45m4
                      寫於 最後由 Pl45m4 編輯
                      #10

                      @SandSnip3r

                      Where I was rude?!
                      BTW: Exactly that bit you quoted from the documentation, I've linked and quoted above already ;-)
                      It is the way it is... the new QtGraphs module uses a QML backend for rendering, even when you use its C++ / QtWidget API


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

                      ~E. W. Dijkstra

                      JonBJ 1 條回覆 最後回覆
                      3
                      • Pl45m4P Pl45m4

                        @SandSnip3r

                        Where I was rude?!
                        BTW: Exactly that bit you quoted from the documentation, I've linked and quoted above already ;-)
                        It is the way it is... the new QtGraphs module uses a QML backend for rendering, even when you use its C++ / QtWidget API

                        JonBJ 離線
                        JonBJ 離線
                        JonB
                        寫於 最後由 編輯
                        #11

                        @Pl45m4 said in Qt Graphs. Building 2d plot using c++ only.:

                        Where I was rude?!

                        You were not rude anywhere, only helpful/to the point. Maybe @SandSnip3r misread or misunderstood.

                        1 條回覆 最後回覆
                        0
                        • S 離線
                          S 離線
                          SandSnip3r
                          寫於 最後由 編輯
                          #12

                          Maybe I misunderstood.

                          Sorry, I'm still having trouble understanding how to use a 2d "QtGraph" from C++. You said "the new QtGraphs module uses a QML backend for rendering, even when you use its C++ / QtWidget API." That's fine, but how do you construct & interact with a 2d "Qt Graph" (which uses a "QML backend")?

                          I see that there are C++ classes for Qt Graphs, like https://doc.qt.io/qt-6/qlineseries.html, but this seems to just be a class which represents data? What's the C++ class which I use as the view? Is there some QWidget-based class which I'd then add the series to?

                          Pl45m4P 1 條回覆 最後回覆
                          0
                          • S SandSnip3r

                            Maybe I misunderstood.

                            Sorry, I'm still having trouble understanding how to use a 2d "QtGraph" from C++. You said "the new QtGraphs module uses a QML backend for rendering, even when you use its C++ / QtWidget API." That's fine, but how do you construct & interact with a 2d "Qt Graph" (which uses a "QML backend")?

                            I see that there are C++ classes for Qt Graphs, like https://doc.qt.io/qt-6/qlineseries.html, but this seems to just be a class which represents data? What's the C++ class which I use as the view? Is there some QWidget-based class which I'd then add the series to?

                            Pl45m4P 離線
                            Pl45m4P 離線
                            Pl45m4
                            寫於 最後由 編輯
                            #13

                            @SandSnip3r said in Qt Graphs. Building 2d plot using c++ only.:

                            What's the C++ class which I use as the view? Is there some QWidget-based class which I'd then add the series to?

                            The QtGraphs Module is still under development.
                            I think the correct class is QGraphsView, but it doesn't seem to exist yet.

                            It's mentioned here as this function returns this type.

                            • https://doc.qt.io/qt-6/qabstractseries.html#graph

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

                            ~E. W. Dijkstra

                            1 條回覆 最後回覆
                            0
                            • S 離線
                              S 離線
                              SandSnip3r
                              寫於 最後由 編輯
                              #14

                              Isn't the Graphs moved out of technical preview as of 6.8? I thought I saw something, but cant find it again, about the qt widgets support for 2d graphs being lagging. Do you know if Qt communicates this roadmap externally? I don't see anything about it the Jira board of known issues.

                              Pl45m4P 1 條回覆 最後回覆
                              0
                              • S 離線
                                S 離線
                                SandSnip3r
                                寫於 最後由 編輯
                                #15

                                Does Graphs even aim to replace the current 2d qt charts? Or is Graphs just meant to be a 3d thing?

                                If it does, is there a way to use the qml-based Qt Graphs from C++?

                                1 條回覆 最後回覆
                                0
                                • S SandSnip3r

                                  Isn't the Graphs moved out of technical preview as of 6.8? I thought I saw something, but cant find it again, about the qt widgets support for 2d graphs being lagging. Do you know if Qt communicates this roadmap externally? I don't see anything about it the Jira board of known issues.

                                  Pl45m4P 離線
                                  Pl45m4P 離線
                                  Pl45m4
                                  寫於 最後由 Pl45m4 編輯
                                  #16

                                  @SandSnip3r said in Qt Graphs. Building 2d plot using c++ only.:

                                  Isn't the Graphs moved out of technical preview as of 6.8?

                                  Should be but as you can see from OPs question QGraphsView, the C++ API to access the QML backend is mentioned in the documentation but not implemented nor it has it's own documentation page... the links lead to nowhere... :(

                                  Maybe use the QML interface for now and handle it like any other hybrid QML/C++ app

                                  QGraphs should be 2D and 3D + C++ and QML... but not everything seem to work right now.


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

                                  ~E. W. Dijkstra

                                  1 條回覆 最後回覆
                                  0
                                  • goldenhawkingG 離線
                                    goldenhawkingG 離線
                                    goldenhawking
                                    編寫 最後由 goldenhawking 編輯
                                    #17

                                    QML uses the local 3D engine of the operating system to render the Plot, rather than the traditional GraphicsView technology used under QtWidgets. This change may be more modern and beneficial for the Qt team to focus on optimizing one framework and reducing costs. The main.qml in the new example is also easy to understand.

                                    The first problem is that the frame rate of QML is low for cheap laptops without independent graphics cards. One important reason for using Qt in the beginning was an example called "10000 chips" (I'm not sure if the number of zeros is correct) , which surprisingly runs very smoothly on old Ubuntu netbooks , with basic Intel core graphics . The rendering effect of QtWidgets achieves the best balance between platform universality, usability, and aesthetics. The new QML is clearly more suitable for mobile devices and morden PCs.

                                    In addition, it is also a common function to directly obtain mouse click messages from internal Chart objects to the outside C++ application , such as calculating new interpolation parameters based on user clicks. Before QtCharts, these were generally implemented using classical Qwt. I think the dense signal slot interaction between QML and C++is another big challenge.

                                    Qt is the best C++ framework I've ever met.

                                    1 條回覆 最後回覆
                                    0
                                    • V Vernat

                                      Hello!! I found GraphsView QML Type, but I did not find it c++ class. I found it in the closed part of the library - qgraphsview_p.h
                                      Why? How to build a 2d plot using C++ classes? QValueAxis and other classes are presented in C++, but not QGraphsView

                                      JKSHJ 離線
                                      JKSHJ 離線
                                      JKSH
                                      Moderators
                                      編寫 最後由 編輯
                                      #18

                                      @Vernat said in Qt Graphs. Building 2d plot using c++ only.:

                                      QValueAxis and other classes are presented in C++, but not QGraphsView

                                      Currently, we can subclass QValueAxis in C++ to add our own functionality, and expose our custom subclass to QML (via QML_ELEMENT).

                                      From what I can see, QGraphsView inherits QQuickItem, so I doubt it's intended to be used in pure C++ (at least not until we have a full-fledged C++ API for Qt Quick). But I've asked Qt R&D for official clarification on QGraphsView: https://bugreports.qt.io/browse/QTBUG-138456

                                      How to build a 2d plot using C++ classes?

                                      From what I can see, there is no public C++ API for 2D graphs at this time. I don't know if it's on the roadmap or not, but there is a C++ API for 3D graphs: https://doc.qt.io/qt-6/graphs-3d-widgets.html

                                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                      1 條回覆 最後回覆
                                      0
                                      • JKSHJ 離線
                                        JKSHJ 離線
                                        JKSH
                                        Moderators
                                        編寫 最後由 編輯
                                        #19

                                        It looks like the GraphsView API will be QML-only. Integration with C++ is done via QQuickWidget: https://doc.qt.io/qt-6/qtgraphs-2d-quickwidgetgraphs-example.html

                                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                        1 條回覆 最後回覆
                                        0
                                        • GrecKoG 離線
                                          GrecKoG 離線
                                          GrecKo
                                          Qt Champions 2018
                                          編寫 最後由 GrecKo 編輯
                                          #20

                                          You can even do it without a .qml file in 6.9 by using the QQuickWidget::setInitialProperties and QQuickWidget::loadFromModule:

                                          QPieSeries* pieSeries = new QPieSeries(&app);
                                          // populate it
                                          QQuickWidget* graphsView = new QQuickWidget();
                                          graphsView->setResizeMode(QQuickWidget::SizeRootObjectToView);
                                          graphsView->setInitialProperties({{"seriesList", QVariant::fromValue(pieSeries)}});
                                          graphsView->loadFromModule("QtGraphs", "GraphsView");
                                          
                                          goldenhawkingG 1 條回覆 最後回覆
                                          2

                                          • 登入

                                          • Login or register to search.
                                          • 第一個貼文
                                            最後的貼文
                                          0
                                          • 版面
                                          • 最新
                                          • 標籤
                                          • 熱門
                                          • 使用者
                                          • 群組
                                          • 搜尋
                                          • Get Qt Extensions
                                          • Unsolved