本文主要是介绍Qt K线图添加通达信标记文字,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Qt K线图添加通达信标记文字,通达信标记文字存储文件为 C:\ctp_shhtqh\T0002\mark.dat 。
void MainWindow::getTipLst()
{QFile file("C:\\ctp_shhtqh\\T0002\\mark.dat");if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){return;}QTextStream in(&file);in.setCodec("GB2312");bool tip = false;QStringList tipLst;while (!in.atEnd()){QString str = in.readLine();if (str == "[TIP]"){tip = true;continue;}if (str == "[TIPWORD]"){break;}if (tip){tipLst.append(str);}}file.close();mTipLst.clear();foreach (QString tip, tipLst){QString word = tip.split("=")[1];if (!word.isEmpty()){mTipLst.append(tip);}}
}
QString tipStr;foreach (QString tip, mTipLst){if (tip.contains(code)){tipStr = tip;}}QMap<QString, QString> tipMap;if (!tipStr.isEmpty()){QStringList tipLst = tipStr.split("=")[1].split("#$");foreach (QString tip, tipLst){QString date = tip.split(" ")[0];QString data = tip.split(" ")[1];if (dateLst.contains(date)){tipMap.insert(date,data);}}}bool tipFlag = false;for (int i = size - 1; i >= 0; --i){StockData data = mStockDataLst.at(i);double high = data.High;double low = data.Low;QStringList tmpLst = data.Date.split("/");QString tipDate = QDate::fromString(QStringLiteral("%1-%2-%3").arg(tmpLst[0]).arg(tmpLst[1]).arg(tmpLst[2]), "yyyy-MM-dd").toString("M.d");pen.setColor(QColor("red"));painter.setPen(pen);if (tipFlag){painter.drawText(offsetX - (klineWidth / 2.0), (max - high) * offsetY + topBottomMargin, tipMap.value(tipDate));}else{painter.drawText(offsetX - (klineWidth / 2.0), (max - low) * offsetY + topBottomMargin + painter.fontMetrics().height(), tipMap.value(tipDate));}tipFlag = !tipFlag;offsetX += offsetX2;}
这篇关于Qt K线图添加通达信标记文字的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!