PyQt-Frameless-Window icon indicating copy to clipboard operation
PyQt-Frameless-Window copied to clipboard

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

Open suterberg opened this issue 1 year ago • 1 comments

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 avatar Nov 16 '23 02:11 suterberg

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

zhiyiYo avatar Nov 26 '23 10:11 zhiyiYo