From b216828f1fe0aab4c4b831702ee1f2c3a61340a2 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Fri, 13 Jun 2025 10:04:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96QTableView\QTreeView\QListVie?= =?UTF-8?q?w=E4=B8=A2=E5=A4=B1=E7=84=A6=E7=82=B9=E6=97=B6item=E7=9A=84?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/attributeTableDelegate.cpp | 5 +++++ ui/connectionDialog.ui | 4 ++++ ui/mainwindow.ui | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/source/attributeTableDelegate.cpp b/source/attributeTableDelegate.cpp index 5ef1543..97dadb7 100644 --- a/source/attributeTableDelegate.cpp +++ b/source/attributeTableDelegate.cpp @@ -150,6 +150,11 @@ void AttributeTableDelegate::paint(QPainter* painter, const QStyleOptionViewItem opt.palette.setColor(QPalette::Text, Qt::red); opt.palette.setColor(QPalette::HighlightedText, Qt::red); } + else + { + //确保失去焦点时高亮颜色,因为上面对于更改的内容会有特殊处理,所以不能放在qss样式中统一处理,qss样式会优先这里被执行 + opt.palette.setColor(QPalette::HighlightedText, QColor(240, 240, 240)); + } //处理被选择时的背景色,注意:如果qss中有设置,会覆盖此处逻辑 if(option.state.testFlag(QStyle::State_Selected)) diff --git a/ui/connectionDialog.ui b/ui/connectionDialog.ui index 706a21a..ca28b99 100644 --- a/ui/connectionDialog.ui +++ b/ui/connectionDialog.ui @@ -66,6 +66,10 @@ QTableView::item:hover QTableView::item:selected { background-color: rgb(49, 91, 125); +} +QTableView::item:selected:!active +{ + color: rgb(240, 240, 240); } diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 6de10dd..780c1bc 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -231,6 +231,10 @@ QTreeView::item:selected { background-color: rgb(49, 91, 125); } +QTreeView::item:selected:!active +{ + color: rgb(240, 240, 240); +} QTreeView::branch:has-children:!has-siblings:closed, QTreeView::branch:closed:has-children:has-siblings { @@ -262,6 +266,10 @@ QListView::item:selected { background-color: rgb(49, 91, 125); } +QListView::item:selected:!active +{ + color: rgb(240, 240, 240); +}