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; };