fix(theme): 复选指示器全局统一(清晰可见,规避Fusion浅底过淡) + 失焦保持选中,移除对象树本地重复样式
This commit is contained in:
parent
2a666663e7
commit
5f02d494dc
|
|
@ -1,5 +1,7 @@
|
||||||
#include "Theme.hpp"
|
#include "Theme.hpp"
|
||||||
|
|
||||||
|
#include "Glyphs.hpp"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
|
@ -155,6 +157,11 @@ QTreeView::item:selected, QListView::item:selected {
|
||||||
background: {{bg/selected}};
|
background: {{bg/selected}};
|
||||||
color: {{text/primary}};
|
color: {{text/primary}};
|
||||||
}
|
}
|
||||||
|
QTreeWidget::item:selected:!active, QListWidget::item:selected:!active,
|
||||||
|
QTreeView::item:selected:!active, QListView::item:selected:!active {
|
||||||
|
background: {{bg/selected}};
|
||||||
|
color: {{text/primary}};
|
||||||
|
}
|
||||||
/* 注意:不要给 QTreeView::branch 设 background——一旦改写 branch,Qt 会停止绘制
|
/* 注意:不要给 QTreeView::branch 设 background——一旦改写 branch,Qt 会停止绘制
|
||||||
默认的展开/折叠箭头(与 indicator 同类陷阱),父节点折叠图标会消失。 */
|
默认的展开/折叠箭头(与 indicator 同类陷阱),父节点折叠图标会消失。 */
|
||||||
|
|
||||||
|
|
@ -449,10 +456,34 @@ ads--CDockWidgetTab[activeTab="true"] QLabel {
|
||||||
}
|
}
|
||||||
)QSS";
|
)QSS";
|
||||||
|
|
||||||
|
// 全局复选指示器:用 writeCheckboxIcon 生成清晰复选框 PNG(未选=明显边框空心框,
|
||||||
|
// 选中=强调色填充+白勾),统一作用于 QCheckBox 与 树/列表的勾选指示器。规避 Fusion
|
||||||
|
// 原生复选框在浅底下边框过淡看不清的问题——全 UI 一套,避免逐控件打补丁。
|
||||||
|
QString indicatorQss(bool dark)
|
||||||
|
{
|
||||||
|
const QColor border = QColor(tokenHex("border/strong", dark));
|
||||||
|
const QColor boxBg = QColor(tokenHex("bg/panel", dark));
|
||||||
|
const QColor accent = QColor(tokenHex("accent/primary", dark));
|
||||||
|
const QString tag = dark ? QStringLiteral("gd") : QStringLiteral("gl"); // 全局缓存标签
|
||||||
|
const QString off = geopro::app::writeCheckboxIcon(false, border, boxBg, Qt::white, tag);
|
||||||
|
const QString on = geopro::app::writeCheckboxIcon(true, accent, accent, Qt::white, tag);
|
||||||
|
return QStringLiteral(
|
||||||
|
"QCheckBox::indicator, QTreeView::indicator, QListView::indicator,"
|
||||||
|
"QTreeWidget::indicator, QListWidget::indicator { width:16px; height:16px; }"
|
||||||
|
"QCheckBox::indicator:unchecked, QTreeView::indicator:unchecked,"
|
||||||
|
"QListView::indicator:unchecked, QTreeWidget::indicator:unchecked,"
|
||||||
|
"QListWidget::indicator:unchecked { image:url(%1); }"
|
||||||
|
"QCheckBox::indicator:checked, QTreeView::indicator:checked,"
|
||||||
|
"QListView::indicator:checked, QTreeWidget::indicator:checked,"
|
||||||
|
"QListWidget::indicator:checked { image:url(%2); }")
|
||||||
|
.arg(off, on);
|
||||||
|
}
|
||||||
|
|
||||||
// 当前模式的全局 QSS。
|
// 当前模式的全局 QSS。
|
||||||
QString styleSheetForMode(bool /*dark*/)
|
QString styleSheetForMode(bool /*dark*/)
|
||||||
{
|
{
|
||||||
return fillTokens(QString::fromUtf8(kStyleSheet));
|
const bool dark = isDarkTheme();
|
||||||
|
return fillTokens(QString::fromUtf8(kStyleSheet)) + indicatorQss(dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调色板同样取自 ElaTheme,让无 QSS 覆盖处的标准控件也与外壳一致。
|
// 调色板同样取自 ElaTheme,让无 QSS 覆盖处的标准控件也与外壳一致。
|
||||||
|
|
|
||||||
|
|
@ -40,30 +40,6 @@ ObjectTreePanel::ObjectTreePanel(QWidget* parent) : QWidget(parent) {
|
||||||
tree_->setHeaderHidden(true);
|
tree_->setHeaderHidden(true);
|
||||||
tree_->setIndentation(14); // 收紧缩进
|
tree_->setIndentation(14); // 收紧缩进
|
||||||
|
|
||||||
// 清晰复选框:自绘 PNG(未选=明显边框空心框,选中=强调色底+白勾),明暗各一套、切换重绘。
|
|
||||||
// 规避 Fusion 原生复选框在浅底下边框过淡、看不清的问题。
|
|
||||||
auto applyCheckboxStyle = [this]() {
|
|
||||||
const bool dark = geopro::app::isDarkTheme();
|
|
||||||
const QColor border = geopro::app::tokenColor("border/strong"); // 未选复选框描边(规范§6.12)
|
|
||||||
const QColor boxBg = geopro::app::tokenColor("bg/panel");
|
|
||||||
const QColor accent = geopro::app::tokenColor("accent/primary"); // 选中填充
|
|
||||||
const QString tag = dark ? QStringLiteral("d") : QStringLiteral("l");
|
|
||||||
const QString off = geopro::app::writeCheckboxIcon(false, border, boxBg, Qt::white, tag);
|
|
||||||
const QString on = geopro::app::writeCheckboxIcon(true, accent, accent, Qt::white, tag);
|
|
||||||
// 选中底/字取语义令牌,与全局树/列表选中一致(规范§6.1/§10)。
|
|
||||||
const QString selBg = geopro::app::token("bg/selected");
|
|
||||||
const QString selFg = geopro::app::token("text/primary");
|
|
||||||
tree_->setStyleSheet(QStringLiteral("QTreeView::indicator{ width:16px; height:16px; }"
|
|
||||||
"QTreeView::indicator:unchecked{ image:url(%1); }"
|
|
||||||
"QTreeView::indicator:checked{ image:url(%2); }"
|
|
||||||
"QTreeView::item:selected{ background:%3; color:%4; }"
|
|
||||||
"QTreeView::item:selected:!active{ background:%3; color:%4; }")
|
|
||||||
.arg(off, on, selBg, selFg));
|
|
||||||
};
|
|
||||||
applyCheckboxStyle();
|
|
||||||
QObject::connect(&ThemeManager::instance(), &ThemeManager::changed, tree_,
|
|
||||||
[applyCheckboxStyle]() { applyCheckboxStyle(); });
|
|
||||||
|
|
||||||
lay->addWidget(tree_, 1);
|
lay->addWidget(tree_, 1);
|
||||||
|
|
||||||
hint_ = new QLabel(QStringLiteral("正在加载对象…"), this);
|
hint_ = new QLabel(QStringLiteral("正在加载对象…"), this);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue