Setting size of QBoxPlot horizontal axis slot.

  • How do you set size of QBoxPlot horizontal axis slot so that there's enough space for each slot to fully show axis value, and scrollbar is generated where total size of all the slots exceed the chartview size? Or, how do you control number of box sets on display in the chartview (if the total number of box sets overflows then scrollbar is generated, like this example

    0_1477140974754_Screenshot from 2016-10-21 18:42:00.png

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QChartView>
    #include <QBoxPlotSeries>
    #include <QBoxSet>
    #include <QValueAxis>
    #include <QBarCategoryAxis>
    #include <QtSql>
    #include <QSqlDatabase>
    #include <QSqlQuery>
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
        QBoxPlotSeries *bidaskSeries = new QBoxPlotSeries(this);
        QStringList categories;
        if (
            QSqlQuery query;
            if (query.exec("SELECT EXTRACT(YEAR FROM month), EXTRACT(MONTH FROM month), bid_low, bid_lowquartile, bid_median, bid_upquartile, bid_high FROM audusd.ts_month_quotebid ORDER BY month"))
                while (
                    categories << query.value(0).toString() + "-" + query.value(1).toString();
                    QBoxSet *set = new QBoxSet();
                    set->setValue(QBoxSet::LowerExtreme, query.value(2).toDouble());
                    set->setValue(QBoxSet::LowerQuartile, query.value(3).toDouble());
                    set->setValue(QBoxSet::Median, query.value(4).toDouble());
                    set->setValue(QBoxSet::UpperQuartile, query.value(5).toDouble());
                    set->setValue(QBoxSet::UpperExtreme, query.value(6).toDouble());
        QChart *chart = new QChart();
        QBarCategoryAxis * axisX = new QBarCategoryAxis();
        chart->addAxis(axisX, Qt::AlignBottom);
        chart->setAxisX(axisX, bidaskSeries);
        QValueAxis *axisY = new QValueAxis();
        chart->addAxis(axisY, Qt::AlignLeft);
        chart->setAxisY(axisY, bidaskSeries);
        axisY->setRange(0.65, 1.15);
        delete ui;

  • Maybe I need to use QGraphicsScene.

    QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. If you want to display a chart in your existing QGraphicsScene, you need to use the QChart (or QPolarChart) class instead.

    The QGraphicsScene class provides a surface for managing a large number of 2D graphical items.

    The class serves as a container for QGraphicsItems. It is used together with QGraphicsView for visualizing graphical items, such as lines, rectangles, text, or even custom items, on a 2D surface. QGraphicsScene is part of the Graphics View Framework.

    QGraphicsScene also provides functionality that lets you efficiently determine both the location of items, and for determining what items are visible within an arbitrary area on the scene. With the QGraphicsView widget, you can either visualize the whole scene, or zoom in and view only parts of the scene.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.