title: Qt - Display a QChartView in a QDialog window
body: <p>I have been following <a href="http://doc.qt.io/qt-5/qtcharts-linechart-example.html" rel="nofollow noreferrer">this example</a> to try create a line chart in a QDialog window. Instead of adding the chart to the UI with:</p>
  
  <pre><code>window.setCentralWidget(chartView);
  </code></pre>
  
  <p>I am adding it to the UI with this line:</p>
  
  <pre><code>QChartView *chartView = new QChartView(chart, ui-&gt;widget_chart);
  </code></pre>
  
  <p>I have a QWidget called widget_chart added to my UI file and a horizontal layout applied. The chart is shown but it is very small. I would have expected that by applying the layout, the chart would take up the full width of the window. And that it would be dynamically resize if I resized the window.</p>
  
  <p><a href="https://i.stack.imgur.com/dZjuM.png" rel="nofollow noreferrer">Screenshot of program</a></p>
  
  <p>How can I make it so that the chart takes up the full width of the QWidget?</p>
  
  <p>Here is the full code for my dialog.cpp file:</p>
  
  <pre><code>#include "dialog.h"
  #include "ui_dialog.h"
  #include &lt;QtCharts&gt;
  
  Dialog::Dialog(QWidget *parent) :
      QDialog(parent),
      ui(new Ui::Dialog)
  {
      ui-&gt;setupUi(this);
  
      QLineSeries *series = new QLineSeries();
  
      series-&gt;append(0, 6);
      series-&gt;append(2, 4);
      series-&gt;append(3, 8);
      series-&gt;append(7, 4);
      series-&gt;append(10, 5);
  
      QChart *chart = new QChart();
      chart-&gt;legend()-&gt;hide();
      chart-&gt;addSeries(series);
      chart-&gt;createDefaultAxes();
      chart-&gt;setTitle("Simple line chart example");
  
      QChartView *chartView = new QChartView(chart, ui-&gt;widget_chart);
      chartView-&gt;setRenderHint(QPainter::Antialiasing);
  
  }
  
  Dialog::~Dialog()
  {
      delete ui;
  }
  </code></pre>