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. qt charts in qgridlayout
Forum Updated to NodeBB v4.3 + New Features

qt charts in qgridlayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 3.2k 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.
  • S Offline
    S Offline
    sieciech
    wrote on last edited by sieciech
    #1

    Hi All,

    i wanted to embedd example: http://doc.qt.io/qt-5/qtcharts-linechart-example.html into qtgridlayout:

    here is constructor of QMainWindow:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        lcdNumber = new QLCDNumber();
        lcdNumber_2 = new QLCDNumber();
        progressBar = new QProgressBar();
    
        lcdNumber->display("wait...");
        m_progress = 0;
        progressBar->setMinimum(0);
        progressBar->setMaximum(59);
        progressBar->setValue(m_progress);
    
        TempChart *tChart = new TempChart();
    
        ui->gridLayout->addWidget(lcdNumber, 0, 0);
        ui->gridLayout->addWidget(lcdNumber_2, 0, 1);
        ui->gridLayout->addWidget(tChart, 1, 0, 1, 2);
        tChart->show();
    }
    

    and constructor of TempChart:

    TempChart::TempChart(QWidget *parent) : QWidget(parent)
    {
         QLineSeries *series = new QLineSeries();
         series->append(0, 6);
         series->append(2, 4);
         series->append(3, 8);
         series->append(7, 4);
         series->append(10, 5);
    
         QChart *chart = new QChart();
         chart->legend()->hide();
         chart->addSeries(series);
         chart->createDefaultAxes();
         chart->setTitle("Simple line chart example");
         chartView = new QChartView(chart);
         chartView->setRenderHint(QPainter::Antialiasing);
    }
    

    Once i exectue it im able to see lcdNumber and lcdNumber_2 on display, however im not able to see my chart on rest of screen. Any ideas why?

    thx in advance for support
    s.

    raven-worxR 1 Reply Last reply
    0
    • S sieciech

      Hi All,

      i wanted to embedd example: http://doc.qt.io/qt-5/qtcharts-linechart-example.html into qtgridlayout:

      here is constructor of QMainWindow:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          lcdNumber = new QLCDNumber();
          lcdNumber_2 = new QLCDNumber();
          progressBar = new QProgressBar();
      
          lcdNumber->display("wait...");
          m_progress = 0;
          progressBar->setMinimum(0);
          progressBar->setMaximum(59);
          progressBar->setValue(m_progress);
      
          TempChart *tChart = new TempChart();
      
          ui->gridLayout->addWidget(lcdNumber, 0, 0);
          ui->gridLayout->addWidget(lcdNumber_2, 0, 1);
          ui->gridLayout->addWidget(tChart, 1, 0, 1, 2);
          tChart->show();
      }
      

      and constructor of TempChart:

      TempChart::TempChart(QWidget *parent) : QWidget(parent)
      {
           QLineSeries *series = new QLineSeries();
           series->append(0, 6);
           series->append(2, 4);
           series->append(3, 8);
           series->append(7, 4);
           series->append(10, 5);
      
           QChart *chart = new QChart();
           chart->legend()->hide();
           chart->addSeries(series);
           chart->createDefaultAxes();
           chart->setTitle("Simple line chart example");
           chartView = new QChartView(chart);
           chartView->setRenderHint(QPainter::Antialiasing);
      }
      

      Once i exectue it im able to see lcdNumber and lcdNumber_2 on display, however im not able to see my chart on rest of screen. Any ideas why?

      thx in advance for support
      s.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @sieciech
      because in your TempChart class you just create a QChartView widget without a parent nor do you add it to a layout.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3
      • S Offline
        S Offline
        sieciech
        wrote on last edited by
        #3

        Thx!!!!

        in fact when i changed:

        ui->gridLayout->addWidget(tChart, 1, 0, 1, 2);
        

        into:

        ui->gridLayout->addWidget(tChart-> chartView, 1, 0, 1, 2);
        

        and chart was present!
        However lcd displays stopped recating on: lcdNumber->display(value), where value shall be updated each second....( previously, without chart it worked as it should). Any ideas?

        regards
        s.

        raven-worxR 1 Reply Last reply
        0
        • S sieciech

          Thx!!!!

          in fact when i changed:

          ui->gridLayout->addWidget(tChart, 1, 0, 1, 2);
          

          into:

          ui->gridLayout->addWidget(tChart-> chartView, 1, 0, 1, 2);
          

          and chart was present!
          However lcd displays stopped recating on: lcdNumber->display(value), where value shall be updated each second....( previously, without chart it worked as it should). Any ideas?

          regards
          s.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @sieciech
          i doubt that just adding it to a layout causes this issue.
          But you also haven't posted any code how the updating of the QLCDNumber widgets actually works.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          • Login

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