Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to implement 'Dynamic Spline Example' to a QMainWindow Project?
Qt 6.11 is out! See what's new in the release blog

How to implement 'Dynamic Spline Example' to a QMainWindow Project?

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 2 Posters 2.1k Views
  • 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
    wrote on last edited by
    #4

    Ok. understood. What is happening ? What is QChartView here ? What is it doing ? Is the Spline not visible in MainWIndow ? Where is it visible ?

    Dheerendra
    @Community Service
    Certified Qt Specialist
    https://www.pthinks.com

    R_IrudezuR 1 Reply Last reply
    0
    • dheerendraD dheerendra

      Ok. understood. What is happening ? What is QChartView here ? What is it doing ? Is the Spline not visible in MainWIndow ? Where is it visible ?

      R_IrudezuR Offline
      R_IrudezuR Offline
      R_Irudezu
      wrote on last edited by R_Irudezu
      #5

      @dheerendra as you see i put the 2nd screenshots code here, first screenshot is my simple QMainWindow project. The problem is i don't know how to insert graphic to widget. Graphic is doing only producing random numbers and draws it.

      Could you show me how to do that, if you know? I mean, show that graphic in that widget in first screenshot.

      Keizoku wa chikaranari.

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #6

        Are you looking for QGraphicsProxyWidget ? If you want to place any graphic items it has to be through this widget or you need to use QGraphicsView & then set this to central widget.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        R_IrudezuR 1 Reply Last reply
        0
        • dheerendraD dheerendra

          Are you looking for QGraphicsProxyWidget ? If you want to place any graphic items it has to be through this widget or you need to use QGraphicsView & then set this to central widget.

          R_IrudezuR Offline
          R_IrudezuR Offline
          R_Irudezu
          wrote on last edited by R_Irudezu
          #7

          @dheerendra I don't know, i am already asking for it. How to do that in a proper way......

          I just shared to code and i want to implement it into QMainWindow (first screenshot), can some show me how to do that.

          Keizoku wa chikaranari.

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
            wrote on last edited by
            #8
            I'm just doing the straight copy from the example. You are also doing the same.  What is the issue you are facing. What is code available here is right.
            
            QMainWindow window;
            Chart *chart = new Chart;
            chart->setTitle("Dynamic spline chart");
            chart->legend()->hide();
            chart->setAnimationOptions(QChart::AllAnimations);
            QChartView chartView(chart);
            chartView.setRenderHint(QPainter::Antialiasing);
            window.setCentralWidget(&chartView);
            window.resize(400, 300);
            window.show();
            

            Dheerendra
            @Community Service
            Certified Qt Specialist
            https://www.pthinks.com

            R_IrudezuR 1 Reply Last reply
            0
            • dheerendraD dheerendra
              I'm just doing the straight copy from the example. You are also doing the same.  What is the issue you are facing. What is code available here is right.
              
              QMainWindow window;
              Chart *chart = new Chart;
              chart->setTitle("Dynamic spline chart");
              chart->legend()->hide();
              chart->setAnimationOptions(QChart::AllAnimations);
              QChartView chartView(chart);
              chartView.setRenderHint(QPainter::Antialiasing);
              window.setCentralWidget(&chartView);
              window.resize(400, 300);
              window.show();
              
              R_IrudezuR Offline
              R_IrudezuR Offline
              R_Irudezu
              wrote on last edited by R_Irudezu
              #9

              Mr. @dheerendra i think you didn't understand the problem. Let's start again :)

              The code i shared here is belong to 'Qt Dynamic Spline Example' project. Nothing wrongs with it, it works. But if you check it out the link and check the project, there is no mainwindow.ui file in that example. But, in my simple project, i have mainwindow.ui file, like i shared in the first screenshot above.

              The code works, but i want to put that graphic example (Qt Dynamic Spline Example) into my simple project and i don't know how to do it, because the example of Qt's class structure seemed different to me.

              If you or someone can show me how to show that Qt example dynamc graphic in a mainwindow.ui widget i'd be glad so much. I want to run that Qt example's dynamic graphic in my widget.

              Here is a GIF:
              ![0_1544407331443_asd.gif](Uploading 100%)

              I exactly want include the animated Qt example into my project, to that what widget below, under "Age Average" label

              Keizoku wa chikaranari.

              1 Reply Last reply
              0
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                wrote on last edited by
                #10

                OK. You have mainwindow.ui and you have done drag&drop of all the visual elements in to it. Now you would like to place the Chart into this. Is this correct question ?

                Dheerendra
                @Community Service
                Certified Qt Specialist
                https://www.pthinks.com

                R_IrudezuR 1 Reply Last reply
                0
                • dheerendraD dheerendra

                  OK. You have mainwindow.ui and you have done drag&drop of all the visual elements in to it. Now you would like to place the Chart into this. Is this correct question ?

                  R_IrudezuR Offline
                  R_IrudezuR Offline
                  R_Irudezu
                  wrote on last edited by
                  #11

                  @dheerendra YES!

                  Keizoku wa chikaranari.

                  1 Reply Last reply
                  0
                  • dheerendraD Offline
                    dheerendraD Offline
                    dheerendra
                    Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                    wrote on last edited by
                    #12

                    Just see the following example. Our top layout is vbox. I have added the chart to that layout.

                    This code is constructor.

                    MainWindow::MainWindow(QWidget *parent) :
                     QMainWindow(parent),
                     ui(new Ui::MainWindow)
                    {
                     ui->setupUi(this);
                     QtCharts::QChartView *chart = new QtCharts::QChartView;
                     ui->verticalLayout->addWidget(chart);
                    }
                    
                    MainWindow::~MainWindow()
                    {
                     delete ui;
                    }
                    

                    Dheerendra
                    @Community Service
                    Certified Qt Specialist
                    https://www.pthinks.com

                    R_IrudezuR 1 Reply Last reply
                    1
                    • dheerendraD dheerendra

                      Just see the following example. Our top layout is vbox. I have added the chart to that layout.

                      This code is constructor.

                      MainWindow::MainWindow(QWidget *parent) :
                       QMainWindow(parent),
                       ui(new Ui::MainWindow)
                      {
                       ui->setupUi(this);
                       QtCharts::QChartView *chart = new QtCharts::QChartView;
                       ui->verticalLayout->addWidget(chart);
                      }
                      
                      MainWindow::~MainWindow()
                      {
                       delete ui;
                      }
                      
                      R_IrudezuR Offline
                      R_IrudezuR Offline
                      R_Irudezu
                      wrote on last edited by
                      #13

                      @dheerendra if you checked it out the Qt's example, constructor has kinda differend structure:

                      Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags):
                          QChart(QChart::ChartTypeCartesian, parent, wFlags),
                          m_series(0),
                          m_axis(new QValueAxis),
                          m_step(0),
                          m_x(5),
                          m_y(1)
                      
                      {
                          //...
                      }
                      

                      and in main.cpp there is

                      Chart *chart = new Chart;
                      QChartView chartView(chart);
                      chartView.setRenderHint(QPainter::Antialiasing);
                      

                      the chart objects you wrote in code and i showed are different in my opinion.

                      Keizoku wa chikaranari.

                      1 Reply Last reply
                      0
                      • dheerendraD Offline
                        dheerendraD Offline
                        dheerendra
                        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                        wrote on last edited by
                        #14

                        Yes. This is where I'm suggesting you to use the QChartView. QChart is QGraphicsItem. You will not be able to directly add in to widget based App. Please use the QChartView. Please add the QChartView to layout. Please look at the sample given by me.

                        Dheerendra
                        @Community Service
                        Certified Qt Specialist
                        https://www.pthinks.com

                        1 Reply Last reply
                        1
                        • R_IrudezuR Offline
                          R_IrudezuR Offline
                          R_Irudezu
                          wrote on last edited by R_Irudezu
                          #15

                          @dheerendra said in How to implement 'Dynamic Spline Example' to a QMainWindow Project?:

                          QChartView *chart = new QtCharts::QChartView;

                          Thank you Mr. @dheerendra

                          OK i am writing here how i solved:

                          • First add chart.h and chart.cpp file to your project or whatever name you want.
                          • Create an instance of Chart :
                          Chart *sampleChart = new Chart;
                          
                          //default values
                          sampleChart ->m_series = 0;
                          sampleChart ->m_axis = new QValueAxis;
                          sampleChart ->m_step = 0;
                          sampleChart ->m_x = 5;
                          sampleChart ->m_y = 1;
                          
                          //connection to the random value producer function
                          QObject::connect(&sampleChart ->m_timer, &QTimer::timeout, sampleChart , &Chart::handleTimeout);
                              sampleChart ->m_timer.setInterval(1250);
                          
                          • Set its customizing features if you want. such as:
                           sampleChart ->setTheme(QChart::ChartThemeDark);
                           sampleChart ->setDropShadowEnabled(true);
                           sampleChart ->setAnimationOptions(QChart::SeriesAnimations);
                          
                          • Insert it into your widget layout:
                          QChartView *chartView = new QChartView;
                          chartView->setChart(m);
                          chartView->setRenderHint(QPainter::Antialiasing);
                          ui->verticalLayout->addWidget(chartView);
                          
                          sampleChart->m_timer.start();
                          

                          a screenshot here:
                          0_1544407038588_asdd.PNG

                          Keizoku wa chikaranari.

                          1 Reply Last reply
                          1
                          • dheerendraD Offline
                            dheerendraD Offline
                            dheerendra
                            Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
                            wrote on last edited by
                            #16

                            Cool. Yes, This is the right way of doing. This is what we suggested you from the beginning.

                            Dheerendra
                            @Community Service
                            Certified Qt Specialist
                            https://www.pthinks.com

                            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