このページでは

StocQt

100銘柄に対応したカスタマイズ可能な株価チャート。

Qt Groupの株価を、3D価格推移チャートと概要パネルとともに表示するStocQtアプリケーション

StocQtアプリケーションは、NASDAQ-100を基にしたユーザー指定の100銘柄のトレンドチャートを表示します。ユーザーはリストから銘柄を選択できます。また、比較チャートで使用するために、最大5銘柄をお気に入り登録することも可能です。

このアプリケーションでは、Search、StockCheckBox、StockChart、StockView、SettingsView といったいくつかのカスタム型を使用しています。これらの型は、株価データを分かりやすい形式で表示し、ユーザーがトレンドチャートをカスタマイズできるようにします。例えば、ユーザーは株価の週次、月次、四半期、半期のトレンドを表示するように選択できます。

このアプリケーションでは、APIリクエストや銘柄のお気に入り登録などのデータ処理のために、C++で実装されたカスタムStockEngineシングルトンを使用しています。また、オンラインデータの取得には、カスタム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 銘柄のグループのトレンドチャートを表示する複雑なデータモデルです。 これらは、StockEngine から ListModel にデータを読み込み、Surface3D、Bars3D、または Scatter3D を使用して株価の推移をグラフ表示する、別のカスタム型である StockChart または FavoriteChart を使用しています。

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"
                }
            },

SettingsViewは、アプリケーションに関する情報を表示します。

このアプリケーションをより深く理解するには、Qt Creator またはVisual Studio Codeを使用してコードを閲覧してください。

例の動作確認

サンプルは、以下の手順で実行できます。

code.qt.io のサンプルプロジェクト

「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.