配色方案有多种类型,可以根据不同的需求和应用场景来选择合适的配色方法。在柱状图、饼状图中都会用到不同的配色,本文将配色方案使用二维数组进行存储,对常用的配色进行了整理:
效果图
示例代码
cpp
void MainWindow::InitUI()
{
QString qss = "QLabel{border: none; border-radius:5px; color: gray;}";
setStyleSheet(qss);
QColor clrArray[18][12] = {
{ "#0780cf", "#765005", "#fa6d1d", "#0e2c82", "#b6b51f", "#da1f18", "#701866", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#63b2ee", "#76da91", "#f8cb7f", "#f89588", "#7cd6cf", "#9192ab", "#7898e1", "#efa666", "#eddd86", "#9987ce", "#63b2ee", "#76da91" },
{ "#71ae46", "#96b744", "#c4cc38", "#ebe12a", "#eab026", "#e3852b", "#d85d2a", "#ce2626", "#ac2026", "#71ae46", "#96b744", "#c4cc38" },
{ "#00a8e1", "#99cc00", "#e30039", "#fcd300", "#800080", "#00994e", "#ff6600", "#808000", "#db00c2", "#008080", "#0000ff", "#c8cc00" },
{ "#3b6291", "#943c39", "#779043", "#624c7c", "#388498", "#bf7334", "#3f6899", "#9c403d", "#7d9847", "#675083", "#3b8ba1", "#c97937" },
{ "#194f97", "#555555", "#bd6b08", "#00686b", "#c82d31", "#625ba1", "#898989", "#9c9800", "#007f54", "#a195c5", "#103667", "#f19272" },
{ "#0e72cc", "#6ca30f", "#f59311", "#fa4343", "#16afcc", "#85c021", "#d12a6a", "#0e72cc", "#6ca30f", "#f59311", "#fa4343", "#16afcc" },
{ "#3682be", "#45a776", "#f05326", "#eed777", "#334f65", "#b3974e", "#38cb7d", "#ddae33", "#844bb3", "#93c555", "#5f6694", "#df3881" },
{ "#95a2ff", "#fa8080", "#ffc076", "#fae768", "#87e885", "#3cb9fc", "#73abf5", "#cb9bff", "#434348", "#90ed7d", "#f7a35c", "#8085e9" },
{ "#fa2c7b", "#ff38e0", "#ffa235", "#04c5f3", "#0066fe", "#8932a5", "#c90444", "#cb9bff", "#434348", "#90ed7d", "#f7a35c", "#8085e9" },
{ "#05f8d6", "#0082fc", "#fdd845", "#22ed7c", "#09b0d3", "#1d27c9", "#f9e264", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#e75840", "#a565ef", "#628cee", "#eb9358", "#d05c7c", "#bb60b2", "#433e7c", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#ef4464", "#fad259", "#d22e8d", "#03dee0", "#d05c7c", "#bb60b2", "#433e7c", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#929fff", "#9de0ff", "#ffa897", "#af87fe", "#7dc3fe", "#bb60b2", "#433e7c", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#50c48f", "#26ccd8", "#3685fe", "#9977ef", "#f5616f", "#f7b13f", "#f9e264", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#bf19ff", "#854cff", "#5f45ff", "#02cdff", "#0090ff", "#314976", "#f9e264", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#45c8dc", "#854cff", "#5f45ff", "#47aee3", "#d5d6d8", "#96d7f9", "#f9e264", "#f47a75", "#009db2", "#024b51", "#0780cf", "#765005" },
{ "#9489fa", "#f06464", "#f7af59", "#f0da49", "#71c16f", "#2aaaef", "#5690dd", "#bd88f5", "#009db2", "#024b51", "#0780cf", "#765005" }
};
QGridLayout *layout = new QGridLayout(this);
ui->vlayout_main->addLayout(layout);
//
for (int r=0; r<18; r++)
{
for (int c=0; c<12; c++)
{
QColor clr = *(*(clrArray + r) + c);
QString style = QString("QLabel{background: rgb(%1,%2,%3)}")
.arg(clr.red()).arg(clr.green()).arg(clr.blue());
QLabel *lbl = new QLabel(QString("%1-%2").arg(r).arg(c));
lbl->setStyleSheet(style);
layout->addWidget(lbl, r, c);
}
}
}