MCPcopy Create free account
hub / github.com/KDAB/KDChart / MainWindow

Method MainWindow

examples/Axis/Labels/mainwindow.cpp:25–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23#include <QTextDocument>
24
25MainWindow::MainWindow(QWidget *parent)
26 : QWidget(parent)
27{
28 setupUi(this);
29
30 auto *chartLayout = new QHBoxLayout(m_chartFrame);
31 m_chart = new KDChart::Chart;
32 chartLayout->addWidget(m_chart);
33
34 m_model.loadFromCSV(":/data");
35
36 // Set up the diagram
37 m_lines = new KDChart::LineDiagram();
38 m_lines->setModel(&m_model);
39
40 m_xAxis = new KDChart::CartesianAxis(m_lines);
41 KDChart::TextAttributes ta(m_xAxis->textAttributes());
42
43 auto *yAxis = new AdjustedCartesianAxis(m_lines);
44 yAxis->setBounds(3, 6);
45 m_xAxis->setPosition(KDChart::CartesianAxis::Bottom);
46 yAxis->setPosition(KDChart::CartesianAxis::Left);
47
48// set the following to 0, to see the default Abscissa labels (== X headers, as read from the data file)
49#if 1
50 QStringList daysOfWeek;
51 daysOfWeek << "Monday"
52 << "Tuesday"
53 << "Wednesday"
54 << "Thursday"
55 << "Friday"
56 << "Saturday"
57 << "Sunday";
58 m_xAxis->setLabels(daysOfWeek);
59
60 // QStringList shortDays;
61 // shortDays << "Mon" << "Tue" << "Wed" << "Thu" << "Fri" << "Sat" << "Sun";
62 // m_xAxis->setShortLabels( shortDays );
63#endif
64
65// Use HTML for drawing the text in the axis labels.
66#if 0
67 QStringList htmlStyles;
68 htmlStyles << "<b>Bold</b>" << "<i>Italic</i>" << "<u>Underline</u>" << "<font color='red'>Red</font>";
69 m_xAxis->setLabels( htmlStyles );
70 ta.setTextDocument(new QTextDocument);
71#endif
72
73 // Illustration of custom ticks
74 QList<qreal> ticks;
75 ticks.append(0.5);
76 ticks.append(3.5);
77 ticks.append(4.2);
78 ticks.append(6.5);
79 m_xAxis->setCustomTicks(ticks);
80 yAxis->setCustomTicks(ticks);
81
82 // rotate abscissa labels by -60 degrees:

Callers

nothing calls this directly

Calls 15

loadFromCSVMethod · 0.80
setBoundsMethod · 0.80
setLabelsMethod · 0.80
setTextDocumentMethod · 0.80
setCustomTicksMethod · 0.80
setCustomTickLengthMethod · 0.80
setModelMethod · 0.45
textAttributesMethod · 0.45
setPositionMethod · 0.45
setRotationMethod · 0.45
setTextAttributesMethod · 0.45
addAxisMethod · 0.45

Tested by

no test coverage detected