代码拉取完成,页面将自动刷新
From 66d11ae4717a846e06a7fc85354993ba2e90ce0e Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinsec.com.cn>
Date: Thu, 26 Oct 2023 14:40:23 +0800
Subject: [PATCH] fix(styleditemdelegate): updateEditorGeometry to update the
wrong size of ItemWidgets in QStyledItemDelegate
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 使用自定义的代理,避免QStyledItemDelegate中错误的使用updateEditorGeometry更新ItemWidget大小
Closes #16513
---
.../widgets/styled-item-delegate.cpp | 33 +++++++++++++++++++
.../widgets/styled-item-delegate.h | 28 ++++++++++++++++
src/lightdm-greeter/widgets/user-list.cpp | 2 ++
3 files changed, 63 insertions(+)
create mode 100644 src/lightdm-greeter/widgets/styled-item-delegate.cpp
create mode 100644 src/lightdm-greeter/widgets/styled-item-delegate.h
diff --git a/src/lightdm-greeter/widgets/styled-item-delegate.cpp b/src/lightdm-greeter/widgets/styled-item-delegate.cpp
new file mode 100644
index 0000000..a5323ce
--- /dev/null
+++ b/src/lightdm-greeter/widgets/styled-item-delegate.cpp
@@ -0,0 +1,33 @@
+/**
+ * Copyright (c) 2020 ~ 2023 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
+#include "styled-item-delegate.h"
+
+StyledItemDelegate::StyledItemDelegate(QObject *parent)
+ : QStyledItemDelegate(parent)
+{
+}
+
+StyledItemDelegate::~StyledItemDelegate()
+{
+}
+
+/**
+ * 避免某些时候QListWidget更新item大小时调用QStyledItemDelegate相关接口错误的更新Editor大小
+*/
+void StyledItemDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const
+{
+ editor->setGeometry(option.rect);
+}
\ No newline at end of file
diff --git a/src/lightdm-greeter/widgets/styled-item-delegate.h b/src/lightdm-greeter/widgets/styled-item-delegate.h
new file mode 100644
index 0000000..e229306
--- /dev/null
+++ b/src/lightdm-greeter/widgets/styled-item-delegate.h
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2020 ~ 2023 KylinSec Co., Ltd.
+ * kiran-session-guard is licensed under Mulan PSL v2.
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
+ * You may obtain a copy of Mulan PSL v2 at:
+ * http://license.coscl.org.cn/MulanPSL2
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
+ * See the Mulan PSL v2 for more details.
+ *
+ * Author: liuxinhao <liuxinhao@kylinsec.com.cn>
+ */
+#pragma once
+
+#include <QStyledItemDelegate>
+
+class StyledItemDelegate : public QStyledItemDelegate
+{
+ Q_OBJECT
+public:
+ StyledItemDelegate(QObject* parent = nullptr);
+ ~StyledItemDelegate();
+
+ void updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem &option,
+ const QModelIndex &index) const override;
+};
\ No newline at end of file
diff --git a/src/lightdm-greeter/widgets/user-list.cpp b/src/lightdm-greeter/widgets/user-list.cpp
index b83efdf..e59fa8b 100644
--- a/src/lightdm-greeter/widgets/user-list.cpp
+++ b/src/lightdm-greeter/widgets/user-list.cpp
@@ -24,6 +24,7 @@
#include "ui_user-list.h"
#include "user-info.h"
#include "user-item.h"
+#include "styled-item-delegate.h"
using namespace QLightDM;
@@ -126,6 +127,7 @@ int UserList::userCount()
void UserList::initUI()
{
setAttribute(Qt::WA_Hover, true);
+ ui->userList->setItemDelegate(new StyledItemDelegate(this));
ui->userList->setFocusPolicy(Qt::ClickFocus);
ui->userList->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->userList->setSelectionMode(QAbstractItemView::SingleSelection);
--
2.27.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。