[UserList] Fix context menu crash by correctly parenting (#7145)

Took 5 minutes

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL
2026-08-17 00:53:43 +02:00
committed by GitHub
parent fe53f9c3eb
commit 3de7882f0c
2 changed files with 10 additions and 6 deletions

View File

@@ -336,11 +336,12 @@ constexpr int UserInfo = Qt::UserRole + 2;
// rows (UserListTWI, which uses QTreeWidgetItem::Type) by this item type.
constexpr int SectionItemType = QTreeWidgetItem::UserType + 1;
UserListItemDelegate::UserListItemDelegate(QTreeWidget *tree,
UserListItemDelegate::UserListItemDelegate(UserListWidget *owner,
QTreeWidget *tree,
const QMap<QString, QPixmap> *avatarCache,
const QMap<QString, QPixmap> *cardArtCache,
const QMap<QString, CardArtParams> *cardArtParamsMap)
: QStyledItemDelegate(tree), tree(tree), avatarCache(avatarCache), cardArtCache(cardArtCache),
: QStyledItemDelegate(tree), tree(tree), owner(owner), avatarCache(avatarCache), cardArtCache(cardArtCache),
cardArtParamsMap(cardArtParamsMap)
{
}
@@ -353,7 +354,7 @@ bool UserListItemDelegate::editorEvent(QEvent *event,
if ((event->type() == QEvent::MouseButtonPress) && index.isValid()) {
QMouseEvent *const mouseEvent = static_cast<QMouseEvent *>(event);
if (mouseEvent->button() == Qt::RightButton) {
static_cast<UserListWidget *>(parent())->showContextMenu(mouseEvent->globalPosition().toPoint(), index);
owner->showContextMenu(mouseEvent->globalPosition().toPoint(), index);
return true;
}
}
@@ -593,8 +594,8 @@ UserListWidget::UserListWidget(TabSupervisor *_tabSupervisor,
userTree->setHeaderHidden(true);
userTree->setRootIsDecorated(false);
userTree->setIconSize(QSize(20, 18));
itemDelegate =
new UserListItemDelegate(userTree, &avatarProvider->cache(), &cardArtProvider->cache(), &cardArtParamsMap);
itemDelegate = new UserListItemDelegate(this, userTree, &avatarProvider->cache(), &cardArtProvider->cache(),
&cardArtParamsMap);
userTree->setItemDelegate(itemDelegate);
userTree->setAlternatingRowColors(true);
userTree->hideColumn(1);

View File

@@ -37,6 +37,7 @@ class QPlainTextEdit;
class Response;
class CommandContainer;
class UserContextMenu;
class UserListWidget;
class QShowEvent;
class BanDialog : public QDialog
@@ -105,12 +106,14 @@ public:
class UserListItemDelegate : public QStyledItemDelegate
{
QTreeWidget *tree;
UserListWidget *owner;
const QMap<QString, QPixmap> *avatarCache;
const QMap<QString, QPixmap> *cardArtCache;
const QMap<QString, CardArtParams> *cardArtParamsMap;
public:
explicit UserListItemDelegate(QTreeWidget *tree,
explicit UserListItemDelegate(UserListWidget *owner,
QTreeWidget *tree,
const QMap<QString, QPixmap> *avatarCache,
const QMap<QString, QPixmap> *cardArtCache,
const QMap<QString, CardArtParams> *cardArtParamsMap);