股票图表
100 种股票的可配置股票图表。

StocQt应用程序以纳斯达克 100 指数为基础,为自定义的 100 种股票列表显示趋势图。用户可从列表中选择股票。该应用程序还允许收藏多达 5 只股票,以便在比较图表中使用。
该程序使用多种自定义类型,如搜索、股票复选框、股票图表、股票视图和设置视图。这些类型以可读形式显示股票数据,并允许用户自定义趋势图。例如,用户可以选择查看每周、每月、每季度或每半年的股价趋势。
该应用程序使用用 C++ 实现的自定义 StockEngine 单例来处理数据,如 API 请求和收藏股票。它实现了一个自定义 APIHandler 类,用于获取在线数据。
void ApiHandler::stockHistory(const QString &symbol, std::function<void(QList<HistoryData>)> onComplete)
应用程序使用ObjectModel 类型访问它所依赖的可视化数据模型。
id: mainWindow ... ListView { id: root ... model: ObjectModel { Item { id: stockContainer width: root.width height: root.height StockView { id: stockView anchors.fill: parent visible: false width: root.width height: root.height stateGroup: stateList } StockListView { id: listView visible: true anchors.fill: parent width: root.width height: root.height stateGroup: stateList } } FavoriteView { id: favoriteView width: root.width height: root.height } SettingsView { id: infoView width: root.width height: root.height } } }
StockListModel 是一个自定义数据模型,其中列出了股票的基本信息,如股票 ID、名称、价值和收藏夹。当用户想从列表中选择其他股票时,本应用程序就会使用该数据模型。
StockView 和 FavoriteView 是复杂的数据模型,可显示所选股票或最多 5 只股票的趋势图。它们使用另一种自定义类型--StockChart 或 FavoriteChart,可将 StockEngine 中的数据加载到 ListModels 中,并使用Surface3D 、Bars3D 或Scatter3D 来显示股票价格的图形趋势。
Rectangle { id: chart ... function updateHistory(){ updateStartDate() let startPoint = StockEngine.stockModel.indexOf(startDate) let totalPoints = StockEngine.stockModel.historyCount() let width = startPoint / 50 for (let i = 0; i < totalPoints; i++) { let epochInDays = StockEngine.stockModel.historyDate(i, false) / 86400 appendSurfacePoint(openModel, width, epochInDays, StockEngine.stockModel.openPrice(i)) appendSurfacePoint(closeModel,width, epochInDays, StockEngine.stockModel.closePrice(i)) appendSurfacePoint(highModel,width, epochInDays, StockEngine.stockModel.highPrice(i)) appendSurfacePoint(lowModel,width, epochInDays, StockEngine.stockModel.lowPrice(i)) } ... Surface3D { id: historyGraph ... Surface3DSeries { id: highSeries visible: true baseColor: "green" shading: Surface3DSeries.Shading.Flat drawMode: Surface3DSeries.DrawSurface itemLabelFormat: "Time: @xLabel High:@yLabel$" ItemModelSurfaceDataProxy { itemModel: highModel rowRole: "row" columnRole: "column" yPosRole: "value" } },
设置视图显示有关应用程序的信息。
要更好地了解应用程序,请使用Qt Creator 浏览其代码。
运行示例
运行示例 Qt Creator,打开Welcome 模式,然后从Examples 中选择示例。更多信息,请参阅Qt Creator: 教程:构建并运行。
另请参阅 QML 应用程序。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.