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 create QChars dynamically??
Forum Updated to NodeBB v4.3 + New Features

how to create QChars dynamically??

Scheduled Pinned Locked Moved Unsolved General and Desktop
qchartqcharts
10 Posts 4 Posters 850 Views 1 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.
  • T Offline
    T Offline
    timob256
    wrote on 29 Aug 2023, 15:59 last edited by timob256
    #1

    i make scrollArea and up this QChars but this erorr , Why ??

    mainwindows.cpp

    ...  
    scrollArea = new QScrollArea(centralwidget);
        scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
        scrollArea->setWidgetResizable(true);
        scrollAreaWidgetContents = new QWidget();
        scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
        scrollAreaWidgetContents->setGeometry(QRect(0, 0, 157, 457));
    
        verticalLayout_2 = new QVBoxLayout(scrollAreaWidgetContents);
        verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
    
    
        scrollArea->setWidget(scrollAreaWidgetContents);
        gridLayout->addWidget(scrollArea, 0, 0, 1, 2);
    ...
    
    
    // добавляем график
    void MainWindow::qpbutton_add_plot_clicked()
    {
        DynamicChart *chart = new DynamicChart( this->scrollAreaWidgetContents );  // Создаем объект динамической графика
       
        verticalLayout_2->addWidget(chart);
       
        scrollArea->setWidget(scrollAreaWidgetContents);
    }
    

    dynamicchart.h

    #ifndef DYNAMICCHART_H
    #define DYNAMICCHART_H
    
    //#include <QChart>
    //#include <QtCharts/QChartGlobal>
    
    #include <QtCharts>
    
    class DynamicChart: public QChart
    {
        Q_OBJECT
    public:
        explicit DynamicChart(QChart *parent = 0);
    
        ~DynamicChart();
    
        static int ResID;   // Статическая переменная, счетчик номеров графика
        int getID();        // Функция для возврата локального номера графика
    
    public slots:
    
    private:
        int ChartID = 0;   // Локальная переменная, номер графика
    };
    
    #endif // DYNAMICCHART_H
    

    dynamicchart.cpp

    #include "dynamicchart.h"
    
    DynamicChart::DynamicChart(QChart *parent) :
        QChart(parent)
    {
        ResID++;            // Увеличение счетчика на единицу
        ChartID = ResID;   /* Присвоение кнопке номера, по которому будет производиться
                             * дальнейшая работа с рисунка
                             * */
    
    }
    
    DynamicChart::~DynamicChart()
    {
    
    }
    /* Метод для возврата значения номера рисунка
     * */
    int DynamicChart::getID()
    {
        return ChartID;
    }
    
    /* Инициализация статической переменной класса.
     * Статическая переменная класса должна инициализироваться в обязательном порядке
     * */
    int DynamicChart::ResID = 0;
    
    C 2 Replies Last reply 29 Aug 2023, 16:46
    0
    • T timob256
      29 Aug 2023, 15:59

      i make scrollArea and up this QChars but this erorr , Why ??

      mainwindows.cpp

      ...  
      scrollArea = new QScrollArea(centralwidget);
          scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
          scrollArea->setWidgetResizable(true);
          scrollAreaWidgetContents = new QWidget();
          scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
          scrollAreaWidgetContents->setGeometry(QRect(0, 0, 157, 457));
      
          verticalLayout_2 = new QVBoxLayout(scrollAreaWidgetContents);
          verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
      
      
          scrollArea->setWidget(scrollAreaWidgetContents);
          gridLayout->addWidget(scrollArea, 0, 0, 1, 2);
      ...
      
      
      // добавляем график
      void MainWindow::qpbutton_add_plot_clicked()
      {
          DynamicChart *chart = new DynamicChart( this->scrollAreaWidgetContents );  // Создаем объект динамической графика
         
          verticalLayout_2->addWidget(chart);
         
          scrollArea->setWidget(scrollAreaWidgetContents);
      }
      

      dynamicchart.h

      #ifndef DYNAMICCHART_H
      #define DYNAMICCHART_H
      
      //#include <QChart>
      //#include <QtCharts/QChartGlobal>
      
      #include <QtCharts>
      
      class DynamicChart: public QChart
      {
          Q_OBJECT
      public:
          explicit DynamicChart(QChart *parent = 0);
      
          ~DynamicChart();
      
          static int ResID;   // Статическая переменная, счетчик номеров графика
          int getID();        // Функция для возврата локального номера графика
      
      public slots:
      
      private:
          int ChartID = 0;   // Локальная переменная, номер графика
      };
      
      #endif // DYNAMICCHART_H
      

      dynamicchart.cpp

      #include "dynamicchart.h"
      
      DynamicChart::DynamicChart(QChart *parent) :
          QChart(parent)
      {
          ResID++;            // Увеличение счетчика на единицу
          ChartID = ResID;   /* Присвоение кнопке номера, по которому будет производиться
                               * дальнейшая работа с рисунка
                               * */
      
      }
      
      DynamicChart::~DynamicChart()
      {
      
      }
      /* Метод для возврата значения номера рисунка
       * */
      int DynamicChart::getID()
      {
          return ChartID;
      }
      
      /* Инициализация статической переменной класса.
       * Статическая переменная класса должна инициализироваться в обязательном порядке
       * */
      int DynamicChart::ResID = 0;
      
      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Aug 2023, 16:46 last edited by
      #2

      @timob256 said in how to create QChars dynamically??:

      QChars but this erorr ,

      Which error?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 29 Aug 2023, 18:24 last edited by
        #3

        Hi,

        Short in the desk: did you add the charts module to your project ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • T Offline
          T Offline
          timob256
          wrote on 30 Aug 2023, 15:15 last edited by
          #4

          @Christian-Ehrlicher
          @SGaist

          QChart is a QGraphicsWidget that you can show in a QGraphicsScene.

          how QChart include in Layout and layout include scrollArea ?

          введите сюда описание изображения

          thank you for your interest in my question

          J 1 Reply Last reply 30 Aug 2023, 15:36
          0
          • T timob256
            29 Aug 2023, 15:59

            i make scrollArea and up this QChars but this erorr , Why ??

            mainwindows.cpp

            ...  
            scrollArea = new QScrollArea(centralwidget);
                scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
                scrollArea->setWidgetResizable(true);
                scrollAreaWidgetContents = new QWidget();
                scrollAreaWidgetContents->setObjectName(QString::fromUtf8("scrollAreaWidgetContents"));
                scrollAreaWidgetContents->setGeometry(QRect(0, 0, 157, 457));
            
                verticalLayout_2 = new QVBoxLayout(scrollAreaWidgetContents);
                verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
            
            
                scrollArea->setWidget(scrollAreaWidgetContents);
                gridLayout->addWidget(scrollArea, 0, 0, 1, 2);
            ...
            
            
            // добавляем график
            void MainWindow::qpbutton_add_plot_clicked()
            {
                DynamicChart *chart = new DynamicChart( this->scrollAreaWidgetContents );  // Создаем объект динамической графика
               
                verticalLayout_2->addWidget(chart);
               
                scrollArea->setWidget(scrollAreaWidgetContents);
            }
            

            dynamicchart.h

            #ifndef DYNAMICCHART_H
            #define DYNAMICCHART_H
            
            //#include <QChart>
            //#include <QtCharts/QChartGlobal>
            
            #include <QtCharts>
            
            class DynamicChart: public QChart
            {
                Q_OBJECT
            public:
                explicit DynamicChart(QChart *parent = 0);
            
                ~DynamicChart();
            
                static int ResID;   // Статическая переменная, счетчик номеров графика
                int getID();        // Функция для возврата локального номера графика
            
            public slots:
            
            private:
                int ChartID = 0;   // Локальная переменная, номер графика
            };
            
            #endif // DYNAMICCHART_H
            

            dynamicchart.cpp

            #include "dynamicchart.h"
            
            DynamicChart::DynamicChart(QChart *parent) :
                QChart(parent)
            {
                ResID++;            // Увеличение счетчика на единицу
                ChartID = ResID;   /* Присвоение кнопке номера, по которому будет производиться
                                     * дальнейшая работа с рисунка
                                     * */
            
            }
            
            DynamicChart::~DynamicChart()
            {
            
            }
            /* Метод для возврата значения номера рисунка
             * */
            int DynamicChart::getID()
            {
                return ChartID;
            }
            
            /* Инициализация статической переменной класса.
             * Статическая переменная класса должна инициализироваться в обязательном порядке
             * */
            int DynamicChart::ResID = 0;
            
            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 30 Aug 2023, 15:32 last edited by
            #5

            @timob256 said in how to create QChars dynamically??:

            DynamicChart(QChart *parent = 0);

            You want a QChart* as argument for the parent (for unknown reason) but this->scrollAreaWidgetContents is not a QChart* so it will not compile.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • T timob256
              30 Aug 2023, 15:15

              @Christian-Ehrlicher
              @SGaist

              QChart is a QGraphicsWidget that you can show in a QGraphicsScene.

              how QChart include in Layout and layout include scrollArea ?

              введите сюда описание изображения

              thank you for your interest in my question

              J Offline
              J Offline
              JonB
              wrote on 30 Aug 2023, 15:36 last edited by
              #6

              @timob256
              In addition to @Christian-Ehrlicher. Are you aware that a QChartView is a QWidget which can be used to display a QChart (just as a QGraphicsView displays a QGraphicsScene). Maybe that is what you are wanting to use here?

              T 1 Reply Last reply 6 Sept 2023, 12:07
              1
              • J JonB
                30 Aug 2023, 15:36

                @timob256
                In addition to @Christian-Ehrlicher. Are you aware that a QChartView is a QWidget which can be used to display a QChart (just as a QGraphicsView displays a QGraphicsScene). Maybe that is what you are wanting to use here?

                T Offline
                T Offline
                timob256
                wrote on 6 Sept 2023, 12:07 last edited by
                #7

                @JonB @Christian-Ehrlicher

                I not andestend how include DynamicChart in DynamicWidget and go this in UI ?

                I'm trying to do it like here, but not with buttons, but with charts

                https://evileg.com/en/post/77/

                J T 2 Replies Last reply 6 Sept 2023, 12:35
                0
                • T timob256
                  6 Sept 2023, 12:07

                  @JonB @Christian-Ehrlicher

                  I not andestend how include DynamicChart in DynamicWidget and go this in UI ?

                  I'm trying to do it like here, but not with buttons, but with charts

                  https://evileg.com/en/post/77/

                  J Offline
                  J Offline
                  JonB
                  wrote on 6 Sept 2023, 12:35 last edited by
                  #8

                  @timob256

                  QChart *chart = new QChart;
                  QChartView *chartView = new QChartView(chart);
                  layout->addWidget(chartView);
                  
                  1 Reply Last reply
                  1
                  • T timob256
                    6 Sept 2023, 12:07

                    @JonB @Christian-Ehrlicher

                    I not andestend how include DynamicChart in DynamicWidget and go this in UI ?

                    I'm trying to do it like here, but not with buttons, but with charts

                    https://evileg.com/en/post/77/

                    T Offline
                    T Offline
                    timob256
                    wrote on 6 Sept 2023, 12:50 last edited by
                    #9

                    @timob256

                    введите сюда описание изображения

                    J 1 Reply Last reply 6 Sept 2023, 12:58
                    0
                    • T timob256
                      6 Sept 2023, 12:50

                      @timob256

                      введите сюда описание изображения

                      J Offline
                      J Offline
                      JonB
                      wrote on 6 Sept 2023, 12:58 last edited by JonB 9 Jun 2023, 12:59
                      #10

                      @timob256
                      There is nothing more to say. Code like the stuff you are using. Replace new QPushButton with code for new QChartView plus its own QChart as above.

                      1 Reply Last reply
                      0

                      5/10

                      30 Aug 2023, 15:32

                      • Login

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