From 9aaa1f4c51d6da41050497c153b2127b2c05a486 Mon Sep 17 00:00:00 2001 From: zhaominyong Date: Tue, 14 Jun 2022 14:50:01 +0800 Subject: [PATCH] =?UTF-8?q?123166=20=E3=80=90UKUI=203.1.4=20=E8=B5=B0?= =?UTF-8?q?=E6=9F=A5=E3=80=91=E3=80=90=E8=AE=BE=E8=AE=A1=E3=80=91=E3=80=90?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E8=BF=98=E5=8E=9F=E3=80=91=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E8=B7=AF=E5=BE=84=E6=A0=B7=E5=BC=8F=E6=9C=89?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kybackup/component/backuplistwidget.cpp | 49 +++++++++++++------------ kybackup/component/backuplistwidget.h | 2 + 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/kybackup/component/backuplistwidget.cpp b/kybackup/component/backuplistwidget.cpp index ffd52ea..0de710b 100755 --- a/kybackup/component/backuplistwidget.cpp +++ b/kybackup/component/backuplistwidget.cpp @@ -1,7 +1,6 @@ #include "backuplistwidget.h" #include #include -#include #include #include #include @@ -9,6 +8,7 @@ #include "../messageboxutils.h" #include "../gsettingswrapper.h" #include "../globalbackupinfo.h" +#include "component/imageutil.h" #define WIDTH_ITEM 36 @@ -25,23 +25,21 @@ MyItemWidget::MyItemWidget(QWidget* parent) : m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); m_label->setIsOriginal(true); - QPushButton *buttonDelete = new QPushButton; - // buttonDelete->setProperty("isWindowButton", 0x2); - // buttonDelete->setProperty("useIconHighlightEffect", 0x8); - buttonDelete->setFlat(true); - buttonDelete->setFixedSize(20, 20); - buttonDelete->setIcon(QIcon::fromTheme("window-close-symbolic")); - buttonDelete->setVisible(false); + m_buttonDelete = new QPushButton; + m_buttonDelete->setFlat(true); + m_buttonDelete->setFixedSize(20, 20); + m_buttonDelete->setIcon(ImageUtil::loadTheme("window-close-symbolic", ":/symbos/window-close-symbolic.png", "white", 20)); + m_buttonDelete->setVisible(false); hlayout->addWidget(m_label); - hlayout->addWidget(buttonDelete); + hlayout->addWidget(m_buttonDelete); hlayout->setAlignment(Qt::AlignLeft); connect(this, &MyItemWidget::setScrollWidth, this, [=](int width) { + this->m_scrollWidth = width; int labelWidth = this->m_label->width(); - this->m_label->setFixedWidth(labelWidth + (m_scrollWidth - width)); + this->m_label->setFixedWidth(labelWidth + (this->m_scrollWidth - width)); this->m_label->setElidedText(this->m_text, Qt::ElideLeft); - m_scrollWidth = width; }); connect(GlobelBackupInfo::inst().getGlobalSignals(), &GlobalSignals::fontChanged, this, [=](int fontSize) { @@ -52,19 +50,21 @@ MyItemWidget::MyItemWidget(QWidget* parent) : this->m_label->setElidedText(this->m_text, Qt::ElideLeft); }); - connect(this, &MyItemWidget::selected, buttonDelete, [=](bool checked) { + connect(this, &MyItemWidget::selected, this, [=](bool checked) { if (checked) { - buttonDelete->setVisible(true); + this->m_buttonDelete->setVisible(true); this->m_label->setFixedWidth(this->width() - 12 - 20 - this->m_scrollWidth); this->m_label->setElidedText(this->m_text, Qt::ElideLeft); + this->m_label->setStyleSheet("color:white"); } else { - buttonDelete->setVisible(false); + this->m_buttonDelete->setVisible(false); this->m_label->setFixedWidth(this->width() - 7 - this->m_scrollWidth); this->m_label->setElidedText(this->m_text, Qt::ElideLeft); + this->m_label->setStyleSheet("color:palette(windowText)"); } }); - connect(buttonDelete, &QPushButton::clicked, this, &MyItemWidget::deleteItem); + connect(m_buttonDelete, &QPushButton::clicked, this, &MyItemWidget::deleteItem); this->setLayout(hlayout); } @@ -78,7 +78,8 @@ void MyItemWidget::setText(const QString& text) } MyItemWidget::~MyItemWidget() -{} +{ +} BackupListWidget::BackupListWidget(QWidget *parent /*= nullptr*/) : QListWidget(parent) @@ -156,14 +157,14 @@ bool BackupListWidget::appendItem(const QString &text) MyItemWidget *widget = new MyItemWidget; this->setItemWidget(item, widget); this->setCurrentRow(-1); + // 必须将scrollToBottom等这种滚动条操作放到判断滚动条是否显示isVisible之前 + this->scrollToBottom(); connect(this, &BackupListWidget::setScrollWidth, widget, &MyItemWidget::setScrollWidth); // 滚动条是否展示 - if (count * WIDTH_ITEM > this->height()) { - QScrollBar *vertScroll = verticalScrollBar(); - if (vertScroll) - emit this->setScrollWidth(vertScroll->size().width()); - } + QScrollBar *vertScroll = verticalScrollBar(); + if (vertScroll->isVisible()) + emit this->setScrollWidth(vertScroll->size().width()); QRect rect = this->visualItemRect(item); widget->setBaseSize(rect.width(), rect.height()); @@ -175,12 +176,15 @@ bool BackupListWidget::appendItem(const QString &text) this->removeItemWidget(item); this->takeItem(this->row(item)); delete item; + this->setCurrentRow(-1); + this->scrollToBottom(); if (this->count() == 0) { this->m_plusLogo->setVisible(true); this->m_plusText->setVisible(true); emit this->deleteEmpty(); } else { - if (this->count() * WIDTH_ITEM <= this->height()) + QScrollBar *vertScrollBar = verticalScrollBar(); + if (!vertScrollBar->isVisible()) emit this->setScrollWidth(0); } }); @@ -189,7 +193,6 @@ bool BackupListWidget::appendItem(const QString &text) m_plusText->setVisible(false); emit this->addedItem(); - this->scrollToBottom(); return true; } diff --git a/kybackup/component/backuplistwidget.h b/kybackup/component/backuplistwidget.h index d61899a..616980c 100755 --- a/kybackup/component/backuplistwidget.h +++ b/kybackup/component/backuplistwidget.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "mylabel.h" class MyItemWidget : public QWidget @@ -30,6 +31,7 @@ signals: private: QString m_text; MyLabel *m_label; + QPushButton *m_buttonDelete; int m_scrollWidth = 0; };