Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QtChart with Qt designer



  • Hello,
    I'm new in Qt. I would like to use QtChart with Qt designer but the QChart widget is not available from Qt designer.
    After some research I found that I had to promote a widget to QChart. So I have the following in the Designer now d6a610df-595e-4eef-a839-578857ff9b40-image.png
    In the constructor I have the following

    m_chart = ui->chartView->chart();
    m_chartView = new QChartView(m_chart, this);
    m_xAxis = new QValueAxis;
    m_xAxis->setMax(1.0);
    m_xAxis->setMin(0.0);
    m_chart->addAxis(m_xAxis, Qt::AlignBottom);
    m_yAxis = new QValueAxis;
    m_yAxis->setMax(1.0);
    m_yAxis->setMin(0.0);
    m_chart->addAxis(m_yAxis, Qt::AlignLeft);
    

    The result looks like that
    d8949c96-d18d-4d0b-899f-0eaf3efa8bd0-image.png

    What can I do to see the graph completele?
    Thank you


  • Lifetime Qt Champion

    Hi
    You are creating a new CharView which has default size so that what you are seeing.
    you should use the one on the form
    ui->chartView
    and as @eyllanesc says delete the "new QChartView" line.

    Promotion is like a Type replacement, so Creator inserts the right type in the UI code
    even in the fom its other type used a placeholder.



  • delete m_chartView = new QChartView(m_chart, this); , is unnecesary.


  • Lifetime Qt Champion

    Hi
    You are creating a new CharView which has default size so that what you are seeing.
    you should use the one on the form
    ui->chartView
    and as @eyllanesc says delete the "new QChartView" line.

    Promotion is like a Type replacement, so Creator inserts the right type in the UI code
    even in the fom its other type used a placeholder.



  • Thank you. Now the chart displays correctly.
    Do know why Qt Chart widget is not available in Qt Designer?


  • Lifetime Qt Champion

    @Bert59
    Hi
    Well its quite some work to make a plugin pr platform and maintain it pr release.
    Since QChart has many types of diagrams with its own properties, i guess
    they simply didn't think it was worth it as it also has many helper classes and
    would require a huge amount of code to be able to create such helper class
    "live" and also set properties on that. Like axis and such.
    https://doc.qt.io/qt-5/qtcharts-module.html

    Also it is using Qt Graphics View Framework and it does not use the same virtual system as QWidgets so
    that would also need to be added to the editor.

    But I'm just guessing :)

    Could be any reason but for Graphics View Framework, you must also set the scene in code and
    The designer cannot be used to set any properties of its items.

    So Maybe QChart just inherited that and providing Designer option for that is just very complicated bordering
    to impossible without heavy assumptions on behalf of the user.



  • @Bert59 If you want to use QChartView in Qt Designer without the promotion then you must compile and install the plugin, in this post I show the procedure: https://stackoverflow.com/questions/48362864/how-to-insert-qchartview-in-form-with-qt-designer/48363007#48363007



  • Thank you for the link.
    Unfortunately I couldn't find a dowload button on the linked page.
    How can I download the files?


  • Lifetime Qt Champion

    @Bert59
    Hi
    In chrome, you can use right click

    alt text

    Or you can go to front page
    https://github.com/qt/qtcharts.git
    and press the big green download.

    and then take the files from the zip directly.


Log in to reply