Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win10 亚克力窗口会卡,现在有部分方法可以解决,请验证一下 #133

Open
suterberg opened this issue Nov 16, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@suterberg
Copy link

suterberg commented Nov 16, 2023

class AcrylicWindow(WindowsFramelessWindow):
""" A frameless window with acrylic effect """

def __init__(self, parent=None):
    super().__init__(parent=parent)
    self.__closedByKey = False
   # self.titleBar.installEventFilter(self)

注册titleBar的事件

def resetAcrylicEffect(self, hWnd):
    if not isGreaterEqualWin10():
        warnings.warn("The acrylic effect is only available on Win10+")
        return

    hWnd = int(hWnd)

    self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_TRANSPARENTGRADIENT.value
    self.winCompAttrData.Attribute = WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value
    self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))

去除导致卡顿的函数

"""def eventFilter(self, watched: QObject, event: QEvent) -> bool:
    print(event)
    if event.type() == QEvent.Type.MouseButtonPress:
        if event.button() == Qt.MouseButton.LeftButton:
            self.windowEffect.resetAcrylicEffect(self.winId())
    elif event.type() == QEvent.Type.MouseButtonRelease:
        if event.button() == Qt.MouseButton.LeftButton:
            self.windowEffect.setAcrylicEffect(self.winId())

    return super().eventFilter(watched, event)"""

def nativeEvent(self, eventType, message):
    """ Handle the Windows message """
    msg = MSG.from_address(message.__int__())
    # handle Alt+F4
    if msg.message==win32con.WM_ENTERSIZEMOVE or msg.message == win32con.WM_ENTERSIZEMOVE:
        self.windowEffect.resetAcrylicEffect(self.winId())
    if msg.message==win32con.WM_EXITSIZEMOVE or msg.message == win32con.WM_EXITSIZEMOVE:
        self.windowEffect.setAcrylicEffect(self.winId())

    return super().nativeEvent(eventType, message)

在demo中检测相关事件并设置亚克力效果

@suterberg suterberg added the enhancement New feature or request label Nov 16, 2023
@zhiyiYo
Copy link
Owner

zhiyiYo commented Nov 26, 2023

不好意思忘记回了,上周测试了效果不错,之后有空可以加上

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants