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 · 5 comments
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

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

@xiaoshu312
Copy link

类 AcrylicWindow(WindowsFramelessWindow): “”“ 具有亚克力效果的无框窗口 ”“”

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中检测相关事件并设置亚克力效果

可以发一个PR吗,看不太懂

@suterberg
Copy link
Author

添加一个注销毛玻璃渲染的函数, 在检测到窗口移动的时候执行注销函数,移动结束后重新设置毛玻璃效果,这没啥看不懂的吧,windows 大部分程序都是这样做的,不然会卡

@xiaoshu312
Copy link

可是我不会啊😭

@suterberg
Copy link
Author

可是我不会啊😭

作者没更新么,这个代码都在那,复制进去就行了啊

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

3 participants