##// END OF EJS Templates
Changes scrollbar policy in qchartwidget
Michal Klocek -
r46:95744bf471a1
parent child
Show More
@@ -1,75 +1,77
1 #include "qchartwidget.h"
1 #include "qchartwidget.h"
2 #include "qchartseries.h"
2 #include "qchartseries.h"
3 #include <QGraphicsView>
3 #include <QGraphicsView>
4 #include <QGraphicsScene>
4 #include <QGraphicsScene>
5 #include <QResizeEvent>
5 #include <QResizeEvent>
6
6
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
8
9 class QChartWidgetPrivate
9 class QChartWidgetPrivate
10 {
10 {
11 public:
11 public:
12 QChartWidgetPrivate(QChartWidget *parent) :
12 QChartWidgetPrivate(QChartWidget *parent) :
13 m_view(0),
13 m_view(0),
14 m_scene(0),
14 m_scene(0),
15 m_chart(0)
15 m_chart(0)
16 {
16 {
17 m_scene = new QGraphicsScene();
17 m_scene = new QGraphicsScene();
18 m_view = new QGraphicsView(parent);
18 m_view = new QGraphicsView(parent);
19 m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
20 m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
19 m_view->setScene(m_scene);
21 m_view->setScene(m_scene);
20 m_chart = new QChart();
22 m_chart = new QChart();
21 m_scene->addItem(m_chart);
23 m_scene->addItem(m_chart);
22 m_view->show();
24 m_view->show();
23 }
25 }
24
26
25 ~QChartWidgetPrivate() {
27 ~QChartWidgetPrivate() {
26 }
28 }
27
29
28 QGraphicsView *m_view;
30 QGraphicsView *m_view;
29 QGraphicsScene *m_scene;
31 QGraphicsScene *m_scene;
30 QChart* m_chart;
32 QChart* m_chart;
31 };
33 };
32
34
33 ///////////////////////////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////////////////////////
34
36
35 QChartWidget::QChartWidget(QWidget *parent) :
37 QChartWidget::QChartWidget(QWidget *parent) :
36 QWidget(parent),
38 QWidget(parent),
37 d_ptr(new QChartWidgetPrivate(this))
39 d_ptr(new QChartWidgetPrivate(this))
38 {
40 {
39 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
41 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
40 }
42 }
41
43
42 QChartWidget::~QChartWidget()
44 QChartWidget::~QChartWidget()
43 {
45 {
44 delete d_ptr;
46 delete d_ptr;
45 }
47 }
46
48
47 void QChartWidget::resizeEvent(QResizeEvent *event)
49 void QChartWidget::resizeEvent(QResizeEvent *event)
48 {
50 {
49 Q_D(QChartWidget);
51 Q_D(QChartWidget);
50 d->m_view->resize(size().width(),size().height());
52 d->m_view->resize(size().width(),size().height());
51 d->m_scene->setSceneRect(0,0,size().width(),size().height());
53 d->m_scene->setSceneRect(0,0,size().width(),size().height());
52 d->m_chart->setSize(size());
54 d->m_chart->setSize(size());
53 QWidget::resizeEvent(event);
55 QWidget::resizeEvent(event);
54 }
56 }
55
57
56 QSize QChartWidget::sizeHint() const
58 QSize QChartWidget::sizeHint() const
57 {
59 {
58 // TODO: calculate size hint based on contents?
60 // TODO: calculate size hint based on contents?
59 return QSize(100, 100);
61 return QSize(100, 100);
60 }
62 }
61
63
62 void QChartWidget::addSeries(QChartSeries* series)
64 void QChartWidget::addSeries(QChartSeries* series)
63 {
65 {
64 Q_D(QChartWidget);
66 Q_D(QChartWidget);
65 d->m_chart->addSeries(series);
67 d->m_chart->addSeries(series);
66 }
68 }
67
69
68 QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
70 QChartSeries* QChartWidget::createSeries(QList<qreal> x, QList<qreal> y, QChartSeries::QChartSeriesType type)
69 {
71 {
70 Q_D(QChartWidget);
72 Q_D(QChartWidget);
71 return d->m_chart->createSeries(x, y, type);
73 return d->m_chart->createSeries(x, y, type);
72 }
74 }
73 #include "moc_qchartwidget.cpp"
75 #include "moc_qchartwidget.cpp"
74
76
75 QTCOMMERCIALCHART_END_NAMESPACE
77 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now