47 lines
2.1 KiB
Diff
47 lines
2.1 KiB
Diff
From d9b440c4fc2192084dd1cb531dd74f0063d8a9de Mon Sep 17 00:00:00 2001
|
|
From: liuxinhao <liuxinhao@kylinsec.com.cn>
|
|
Date: Thu, 1 Dec 2022 16:37:12 +0800
|
|
Subject: [PATCH 2/3] fix(KiranSiderbarWidget): If the text is too wide and too
|
|
long, it will be omitted
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
- 文本过宽过长超过分配空间大小的情况下,对文本进行省略
|
|
---
|
|
.../kiran-sidebar-widget/kiran-siderbar-delegate.cpp | 11 ++++++++++-
|
|
1 file changed, 10 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/widgets/kiran-sidebar-widget/kiran-siderbar-delegate.cpp b/src/widgets/kiran-sidebar-widget/kiran-siderbar-delegate.cpp
|
|
index f900fef..2ad8fbe 100644
|
|
--- a/src/widgets/kiran-sidebar-widget/kiran-siderbar-delegate.cpp
|
|
+++ b/src/widgets/kiran-sidebar-widget/kiran-siderbar-delegate.cpp
|
|
@@ -84,7 +84,9 @@ void KiranSiderbarDelegate::paint(QPainter *painter, const QStyleOptionViewItem
|
|
{
|
|
//将存储的数据根据locale转换
|
|
QString text = textForRole(Qt::DisplayRole, displayVar, option.locale);
|
|
- drawDisplay(painter, opt, textRect, text);
|
|
+ //处理文本过宽,超出分配的空间时,对文本进行省略
|
|
+ QString elideText = option.fontMetrics.elidedText(text, Qt::ElideRight, textRect.width(),Qt::TextShowMnemonic);
|
|
+ drawDisplay(painter, opt, textRect, elideText);
|
|
}
|
|
|
|
//status desc
|
|
@@ -265,6 +267,13 @@ void KiranSiderbarDelegate::doLayout(const QStyleOptionViewItem &option, const Q
|
|
int textSpaceX = pixmapSize.isEmpty() ? pixmapRectTemp.right() : pixmapRectTemp.right() + 10;
|
|
int textSpaceWidth = statusDescRectTemp.left() - (statusDescSize.isEmpty() ? 0 : 10) - textSpaceX;
|
|
QRect textRectTemp = QRect(textSpaceX, rect.y(), textSpaceWidth, rect.height());
|
|
+
|
|
+ //对TextSize进行限制,若文字大小超出了剩余的控空间大小,调整为剩余控件大小
|
|
+ if ( textSize.width() > textRectTemp.width() )
|
|
+ {
|
|
+ textSize.setWidth(textRectTemp.width());
|
|
+ }
|
|
+
|
|
textRect.setSize(textSize);
|
|
if (option.displayAlignment & Qt::AlignLeft)
|
|
{
|
|
--
|
|
2.33.0
|
|
|