From c636e0882be1f33e7fa09125d65f802edc0249c3 Mon Sep 17 00:00:00 2001
From: zty199 <46324746+zty199@users.noreply.github.com>
Date: Sat, 31 Dec 2022 23:05:36 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20ISSUE=20#I68566=20=E4=B8=8B=E8=BD=BD?=
=?UTF-8?q?=E5=88=97=E8=A1=A8=E9=94=99=E4=BD=8D=EF=BC=8C=E5=9B=BE=E6=A0=87?=
=?UTF-8?q?=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
DownloadItem 原始定义高度为 54px,上下边距各 4px;然而图片 label 高度定义为 48,且宽度未定义,明显放不下;DownloadListWidget 中添加 item 时,设置每个 item sizeHint 高度只有 50px,与 item 高度不一致
Log: 固定 DownloadItem 高度为 56px;修改 DownloadListWidget 添加 item 时每个 item 的 sizeHint 高度;使用 DLabel 替换 QLabel 用于单个 item 中应用名称显示,使用 setElideMode 保证名称过长时右边显示省略号,并添加鼠标悬浮提示
---
src/widgets/common/downloaditem.cpp | 3 +
src/widgets/common/downloaditem.ui | 95 +++++++++++++++++++----------
src/widgets/downloadlistwidget.cpp | 2 +-
src/widgets/downloadlistwidget.ui | 8 ++-
4 files changed, 75 insertions(+), 33 deletions(-)
diff --git a/src/widgets/common/downloaditem.cpp b/src/widgets/common/downloaditem.cpp
index 30047f8..4c1e179 100644
--- a/src/widgets/common/downloaditem.cpp
+++ b/src/widgets/common/downloaditem.cpp
@@ -22,6 +22,8 @@ DownloadItem::DownloadItem(QWidget *parent) : QWidget(parent),
ui->pushButton_3->hide();
ui->widget_spinner->start();
ui->widget_spinner->hide();
+
+ ui->label->setElideMode(Qt::TextElideMode::ElideRight);
}
DownloadItem::~DownloadItem()
@@ -48,6 +50,7 @@ void DownloadItem::setMax(qint64 max)
void DownloadItem::setName(QString name)
{
ui->label->setText(name);
+ ui->label->setToolTip(name);
}
QString DownloadItem::getName()
diff --git a/src/widgets/common/downloaditem.ui b/src/widgets/common/downloaditem.ui
index 2d57cf3..a02e136 100644
--- a/src/widgets/common/downloaditem.ui
+++ b/src/widgets/common/downloaditem.ui
@@ -7,13 +7,25 @@
<x>0</x>
<y>0</y>
<width>666</width>
- <height>54</height>
+ <height>56</height>
</rect>
</property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>56</height>
+ </size>
+ </property>
<property name="maximumSize">
<size>
<width>16777215</width>
- <height>54</height>
+ <height>56</height>
</size>
</property>
<property name="windowTitle">
@@ -40,10 +52,22 @@
</property>
<item>
<widget class="QLabel" name="label_3">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>48</width>
+ <height>48</height>
+ </size>
+ </property>
<property name="maximumSize">
<size>
<width>48</width>
- <height>16777215</height>
+ <height>48</height>
</size>
</property>
<property name="text">
@@ -52,6 +76,9 @@
<property name="scaledContents">
<bool>true</bool>
</property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
</widget>
</item>
<item>
@@ -70,6 +97,31 @@
</property>
</spacer>
</item>
+ <item>
+ <widget class="DLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="minimumSize">
+ <size>
+ <width>80</width>
+ <height>48</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>48</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </widget>
+ </item>
<item>
<widget class="QLabel" name="label_filename">
<property name="maximumSize">
@@ -83,33 +135,6 @@
</property>
</widget>
</item>
- <item>
- <widget class="QLabel" name="label">
- <property name="minimumSize">
- <size>
- <width>80</width>
- <height>0</height>
- </size>
- </property>
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>16777215</height>
- </size>
- </property>
- <property name="font">
- <font>
- <pointsize>13</pointsize>
- </font>
- </property>
- <property name="text">
- <string>Name</string>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
@@ -153,11 +178,14 @@
<property name="leftMargin">
<number>0</number>
</property>
+ <property name="topMargin">
+ <number>8</number>
+ </property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
- <number>0</number>
+ <number>8</number>
</property>
<item>
<widget class="QProgressBar" name="progressBar">
@@ -297,6 +325,11 @@
<header location="global">dspinner.h</header>
<container>1</container>
</customwidget>
+ <customwidget>
+ <class>DLabel</class>
+ <extends>QLabel</extends>
+ <header>dlabel.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
diff --git a/src/widgets/downloadlistwidget.cpp b/src/widgets/downloadlistwidget.cpp
index 01a7157..28a31f3 100644
--- a/src/widgets/downloadlistwidget.cpp
+++ b/src/widgets/downloadlistwidget.cpp
@@ -91,7 +91,7 @@ void DownloadListWidget::addItem(QString name, QString fileName, QString pkgName
di->pkgName = pkgName;
di->seticon(icon);
QListWidgetItem *pItem = new QListWidgetItem();
- pItem->setSizeHint(QSize(240, 50));
+ pItem->setSizeHint(QSize(240, 56)); // ui 中单个 downloaditem 高度固定 56px(上下 margin 8px,图片固定 48x48)
ui->listWidget->addItem(pItem);
ui->listWidget->setItemWidget(pItem, di);
if (!isBusy)
diff --git a/src/widgets/downloadlistwidget.ui b/src/widgets/downloadlistwidget.ui
index 16cb680..e46a655 100644
--- a/src/widgets/downloadlistwidget.ui
+++ b/src/widgets/downloadlistwidget.ui
@@ -85,7 +85,7 @@ QListWidget::item::selected
}</string>
</property>
<property name="frameShape">
- <enum>QFrame::StyledPanel</enum>
+ <enum>QFrame::NoFrame</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAsNeeded</enum>
@@ -99,9 +99,15 @@ QListWidget::item::selected
<property name="autoScrollMargin">
<number>10</number>
</property>
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
<property name="resizeMode">
<enum>QListView::Fixed</enum>
</property>
+ <property name="spacing">
+ <number>4</number>
+ </property>
</widget>
</item>
<item>