From c4f525496ff1718524db6ccb865eaa06d43cfa82 Mon Sep 17 00:00:00 2001 From: tanjing Date: Wed, 31 Jan 2024 14:04:01 +0800 Subject: [PATCH] =?UTF-8?q?issues#I8XUSP=20qtreeview=E7=84=A6=E7=82=B9?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ukui-config-style.cpp | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp index 26f8505..1377783 100644 --- a/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp +++ b/ukui-styles/qt5-config-style-ukui/ukui-config-style.cpp @@ -1498,7 +1498,24 @@ void UKUIConfigStyle::drawPrimitive(QStyle::PrimitiveElement element, const QSty return; } case PE_FrameFocusRect: { - if (qobject_cast(widget)) + if (qApp->focusWidget() && qApp->focusWidget()->inherits("QTreeView")) + { + sp->initConfigTreeParameters(isUseDarkPalette(), option, widget); + QPen focusPen = sp->m_TreeParameters.treeFocusPen; + painter->save(); + painter->setBrush(Qt::NoBrush); + painter->setPen(focusPen); + int width = focusPen.width(); + if(width == 1 && sp->m_TreeParameters.radius != 0) + painter->translate(0.5, 0.5); + painter->setRenderHint(QPainter::Antialiasing, sp->m_TreeParameters.radius != 0); + + painter->drawRoundedRect(option->rect.adjusted(width/2, width/2, -width/2, -width/2), + sp->m_TreeParameters.radius, sp->m_TreeParameters.radius); + painter->restore(); + return; + } + else if (qobject_cast(widget)) return; break; } @@ -3331,7 +3348,27 @@ void UKUIConfigStyle::drawPrimitive(QStyle::PrimitiveElement element, const QSty painter->drawPath(path); painter->restore(); } - else if(isTree){ +// else if(isTree){ +// if(focus){ +// auto tree = qobject_cast(widget); +// QRect treeItemRec = QRect(tree->viewport()->x(), option->rect.y(), tree->width(), option->rect.height()); +// qDebug() << "treeItemRec......" << treeItemRec; + +// QStyleOptionFocusRect o; +// o.QStyleOption::operator=(*vi); +// o.rect = treeItemRec;//proxy()->subElementRect(SE_ItemViewItemFocusRect, vi, widget); +// qDebug() << "ooooooo" << o.rect << proxy()->subElementRect(SE_TreeViewDisclosureItem, vi, widget); +// painter->save(); +// painter->setPen(QPen(QColor(Qt::blue), 1)); +// painter->setBrush(Qt::NoBrush); +// painter->drawRect(o.rect); +// painter->restore(); + +// drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter, tree); +// auto t = const_cast(tree); +// t->setProperty("focusRect", vi->rect); + //drawPrimitive(QStyle::PE_IndicatorBranch, option, painter, tree); +// } // auto tree = qobject_cast(widget); // auto t = const_cast(tree); // tree->model()->index() @@ -3359,7 +3396,7 @@ void UKUIConfigStyle::drawPrimitive(QStyle::PrimitiveElement element, const QSty // painter->restore(); // } // } - } +// } return; } break;