备份列表控件优化

This commit is contained in:
zhaominyong 2022-03-03 14:37:16 +08:00
parent 11137dfbc2
commit a32dd09a23
2 changed files with 8 additions and 21 deletions

View File

@ -49,34 +49,23 @@ BackupListWidget::BackupListWidget(QWidget *parent /*= nullptr*/) :
connect(this, &BackupListWidget::currentItemChanged, this, [=](QListWidgetItem *current, QListWidgetItem *previous) {
if (current) {
MyItemWidget *widget = qobject_cast<MyItemWidget *>(this->itemWidget(current));
emit widget->selected(true);
if (widget)
emit widget->selected(true);
}
if (previous) {
MyItemWidget *widget = qobject_cast<MyItemWidget *>(this->itemWidget(previous));
emit widget->selected(false);
if (widget)
emit widget->selected(false);
}
repaint();
// repaint();
});
}
BackupListWidget::~BackupListWidget()
{}
int BackupListWidget::findIndexOfItem(QListWidgetItem *item)
{
int index = -1;
for (int row = 0; row < this->count(); ++row) {
if (item == this->item(row)) {
index = row;
break;
}
}
return index;
}
bool BackupListWidget::contains(const QString& text)
{
// 1、针对使用addItem等的正规使用场景展示内容在原生item上
@ -136,9 +125,10 @@ bool BackupListWidget::appendItem(const QString &text)
buttonDelete->setVisible(false);
});
connect(buttonDelete, &QPushButton::clicked, [=]() {
connect(buttonDelete, &QPushButton::clicked, this, [=]() {
this->m_List.removeOne(label->text());
this->takeItem(this->findIndexOfItem(item));
this->removeItemWidget(item);
this->takeItem(this->row(item));
delete item;
if (this->count() == 0) {
m_plusLogo->setVisible(true);

View File

@ -27,9 +27,6 @@ public:
// 添加列表项注意使用本类的功能不能用addItem等基类添加项的方法
bool appendItem(const QString &text);
// 根据QListWidgetItem*查找项对应的索引序号
int findIndexOfItem(QListWidgetItem *item);
// 判断列表项是否包含text注意使用时不能用findItems等基类查找方法
bool contains(const QString &text);