fix(styleditemdelegate): updateEditorGeometry to update the wrong size of ItemWidgets in QStyledItemDelegate

- 使用自定义的代理,避免QStyledItemDelegate中错误的使用updateEditorGeometry更新ItemWidget大小

Closes #16513
This commit is contained in:
liuxinhao 2023-10-26 14:53:04 +08:00
parent 20724e42ff
commit b413a2f43f
2 changed files with 123 additions and 1 deletions

View File

@ -0,0 +1,118 @@
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.33.0

View File

@ -1,6 +1,6 @@
Name: kiran-session-guard
Version: 2.5.1
Release: 6
Release: 7
Summary: Kiran desktop environment login and lock screen dialog
Summary(zh_CN): Kiran桌面环境登录和解锁框
@ -14,6 +14,7 @@ Patch0004: 0004-fix-crash-block-Fixed-the-crash-caused-by-the-exit-s.patch
Patch0005: 0005-fix-avatar-Update-authentication-users-and-user-list.patch
Patch0006: 0006-fix-compile-warning-Fixed-some-compilation-warnings.patch
Patch0007: 0007-fix-kiran-session-guard-fits-the-Qt5.9.7-interface.patch
Patch0008: 0008-fix-styleditemdelegate-updateEditorGeometry-to-updat.patch
%define SHOW_VIRTUAL_KEYBOARD 0
@ -152,6 +153,9 @@ gtk-update-icon-cache -f /usr/share/icons/hicolor/
rm -rf %{buildroot}
%changelog
* Thu Oct 26 2023 liuxinhao <liuxinhao@kylinsec.com.cn> - 2.5.1-7
- KYOS-F: fix updateEditorGeometry to update the wrong size of ItemWidgets in QStyledItemDelegate(#16513)
* Tue Sep 12 2023 yinhongchang <yinhongchang@kylinsec.com.cn> - 2.5.1-6
- KYOS-F: fits the Qt5.9.7 interface(#15019)