1

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();
}

graphic i want to add

Hma
  • 9
  • 3
  • 1
    As far as I know this is not possible. `QtQuick` and `QWidget` are completely different technologies. – folibis Oct 03 '22 at 11:14
  • Some answers are here https://stackoverflow.com/questions/13014415/qt5-embed-qwidget-object-in-qml Though the opposite direction of embedding QML into a QWidget is possible with `QQuickWidget`. I would however definitely not recommend mixing QML and QtWidgets in one application. – HiFile.app - best file manager Oct 03 '22 at 15:07
  • thank you for the replies. I will review the article you shared. I need to embed ready graphics in qml window. I couldn't find any qml example the way I want it. I added the image of the graphic I wanted under the subject. – Hma Oct 04 '22 at 06:53
  • https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1577731783#N1577871231 Here's a simple version of the chart that I've visualized, converted to qml. Based on this example, I converted the 3-graphic version to qml. Friends in need can use it. – Hma Oct 31 '22 at 11:31

0 Answers0