I have a separate qml that I call inside my main window. Inside this qml I want to show the following chart as it is. Is something like this possible? I will be grateful if you could help me. Thanks in advance.
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QUrl("qrc:/QmlSources/main.qml")));
return app.exec();
I can open the chart in a separate window with RealTimeMultiChart realTimeMultiChart; realTimeMultiChart.exec();
//
// Constructor
//
RealTimeMultiChart::RealTimeMultiChart(QWidget *parent) :
QDialog(parent)
{
//
// Set up the GUI
//
setFixedSize(772, 60 + 3 * chartHeight + xAxisHeight);
setWindowTitle("Real-Time MultiChart with Zoom/Scroll and Track Line");
QFrame *frame = new QFrame(this);
frame->setGeometry(4, 4, 120, height() - 8);
frame->setFrameShape(QFrame::StyledPanel);
// Chart Viewer
m_ChartViewer = new QChartViewer(this);
m_ChartViewer->setGeometry(128, 4, 640, 350);
connect(m_ChartViewer, SIGNAL(viewPortChanged()), SLOT(onViewPortChanged()));
connect(m_ChartViewer, SIGNAL(mouseMovePlotArea(QMouseEvent*)),
SLOT(onMouseMovePlotArea(QMouseEvent*)));
// Horizontal scroll bar
m_HScrollBar = new QScrollBar(Qt::Horizontal, this);
m_HScrollBar->setGeometry(128, height() - 18, 640, 18);
connect(m_HScrollBar, SIGNAL(valueChanged(int)), SLOT(onHScrollBarChanged(int)));
// Clear data arrays to Chart::NoValue
for (int i = 0; i < sampleSize; ++i)
m_timeStamps[i] = m_dataSeriesA[i] = m_dataSeriesB[i] = m_dataSeriesC[i] = Chart::NoValue;
m_currentIndex = 0;
// Set m_nextDataTime to the current time. It is used by the real time random number
// generator so it knows what timestamp should be used for the next data point.
m_nextDataTime = QDateTime::currentDateTime();
// Initially set the mouse to drag to scroll mode.
pointerPB->click();
// Enable mouse wheel zooming by setting the zoom ratio to 1.1 per wheel event
m_ChartViewer->setMouseWheelZoomRatio(1.1);
// Set up the data acquisition mechanism. In this demo, we just use a timer to get a
// sample every 250ms.
QTimer *dataRateTimer = new QTimer(this);
dataRateTimer->start(DataInterval);
connect(dataRateTimer, SIGNAL(timeout()), SLOT(onDataTimer()));
// Set up the chart update timer
m_ChartUpdateTimer = new QTimer(this);
connect(m_ChartUpdateTimer, SIGNAL(timeout()), SLOT(onChartUpdateTimer()));
// Can start now
m_ChartUpdateTimer->start();
}