zhiyiYo / PyQt-Fluent-Widgets

A fluent design widgets library based on C++ Qt/PyQt/PySide. Make Qt Great Again.
https://qfluentwidgets.com
GNU General Public License v3.0
5.8k stars 562 forks source link

[Bug]: 【严重bug】菜单条多级菜单下显示 BUG #973

Closed Kwen-Chen closed 2 months ago

Kwen-Chen commented 2 months ago

What happened?

如下图所示:多级菜单条,如果存在两个子菜单条,正常显示如下:

image

但多次打开后如下:

image

中间出现断层,且会越来越远

Operation System

Windows 11、Windows 10、Mac Os 15.0 都存在该问题

Python Version

3.8.10 64bit

PyQt/PySide Version

PyQt 5.15.11

PyQt/PySide-Fluent-Widgets Version

v1.6.5

How to Reproduce?

多级菜单条,执行代码,单击 “文件”, 然后点击空白处,再重新点击 “文件”,即可复现

Minimum code

import json
import os
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication
from qfluentwidgets import CommandBar, TransparentDropDownPushButton, FluentIcon, RoundMenu, Action
from qfluentwidgets.components.widgets.frameless_window import FramelessWindow

class MainWindow(FramelessWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        # 新增 Commandbar
        self.CommandBar = CommandBar(self)
        self.init_ui()

    def init_ui(self):

        # 菜单条
        self.CommandBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
        # 文件
        menu_file = TransparentDropDownPushButton('文件', self, FluentIcon.FOLDER)
        menu = RoundMenu(parent=self)
        menu_file.setMenu(menu)

        # 文件-新建
        action_new = Action(FluentIcon.ADD, '新建', menu)
        menu.addAction(action_new)

        # 文件-选择项目
        menu_project = RoundMenu('选择项目', self)
        projects = ['项目1', '项目2', '项目3']
        for project in projects:
            action_project = Action(FluentIcon.FOLDER, project, menu_project)
            menu_project.addAction(action_project)

        menu.addMenu(menu_project)

        self.CommandBar.addWidget(menu_file)

if __name__ == '__main__':
    # 高分屏适配
    QApplication.setHighDpiScaleFactorRoundingPolicy(
        Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    app = QApplication(sys.argv)

    window = MainWindow()
    window.showMaximized()

    sys.exit(app.exec_())
zhiyiYo commented 2 months ago

重复 issue