Skip to content

Commit 8980f8b

Browse files
committed
fix: correct context menu coordinate mapping
Changed the DockContextMenu parent from 'this' to 'nullptr' in PluginItem constructor to fix coordinate mapping issues when right-click menu is shown. The issue occurred because using 'this' as parent caused the menu's coordinate system to be relative to the PluginItem widget, leading to incorrect position mapping when the menu was displayed. By setting parent to nullptr, the menu becomes a top-level widget with screen coordinates, ensuring proper positioning. Also added explicit cleanup in destructor to safely delete the menu pointer. Log: Fixed incorrect right-click menu position for dock plugin items fix: 修复上下文菜单坐标映射问题 将 PluginItem 构造函数中 DockContextMenu 的父对象从 'this' 改为 'nullptr',以修复显示右键菜单时的坐标映射问题。问题原因是使用 'this' 作 为父对象会导致菜单的坐标系相对于 PluginItem 小部件,从而在显示菜单时产 生错误的位置映射。通过将父对象设置为 nullptr,菜单成为使用屏幕坐标的顶 层小部件,确保正确定位。同时在析构函数中添加了显式清理逻辑以安全删除菜单 指针。 Log: 修复了任务栏插件项右键菜单位置不正确的问题 PMS: BUG-352159
1 parent e82424b commit 8980f8b

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/loader/pluginitem.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -19,7 +19,7 @@ PluginItem::PluginItem(PluginsItemInterface *pluginItemInterface, const QString
1919
: QWidget(parent)
2020
, m_itemKey(itemKey)
2121
, m_pluginsItemInterface(pluginItemInterface)
22-
, m_menu(new DockContextMenu(this))
22+
, m_menu(new DockContextMenu(nullptr))
2323
, m_tooltipTimer(new QTimer(this))
2424
, m_tipsWidget(nullptr)
2525
{
@@ -44,7 +44,13 @@ PluginItem::PluginItem(PluginsItemInterface *pluginItemInterface, const QString
4444
});
4545
}
4646

47-
PluginItem::~PluginItem() = default;
47+
PluginItem::~PluginItem()
48+
{
49+
if (m_menu) {
50+
delete m_menu;
51+
m_menu = nullptr;
52+
}
53+
}
4854

4955
QWidget *PluginItem::itemPopupApplet()
5056
{

0 commit comments

Comments
 (0)