提交 d557dfd2 编写于 作者: 之一Yo's avatar 之一Yo

添加 SnapLayout 功能(#230)

上级 d2ac0e23
import sys
if sys.platform != "win32":
from qframelesswindow import FramelessWindow
else:
from ctypes.wintypes import MSG
import win32con
from PyQt5.QtCore import QPoint, QEvent, Qt
from PyQt5.QtGui import QCursor, QMouseEvent
from PyQt5.QtWidgets import QApplication
from qframelesswindow import FramelessWindow as Window
from qframelesswindow.titlebar.title_bar_buttons import TitleBarButtonState
class FramelessWindow(Window):
""" Frameless window """
def nativeEvent(self, eventType, message):
""" Handle the Windows message """
msg = MSG.from_address(message.__int__())
if not msg.hWnd:
return super().nativeEvent(eventType, message)
if msg.message == win32con.WM_NCHITTEST and self._isResizeEnabled:
if self._isHoverMaxBtn():
self.titleBar.maxBtn.setState(TitleBarButtonState.HOVER)
return True, win32con.HTMAXBUTTON
elif msg.message in [0x2A2, win32con.WM_MOUSELEAVE]:
self.titleBar.maxBtn.setState(TitleBarButtonState.NORMAL)
elif msg.message in [win32con.WM_NCLBUTTONDOWN, win32con.WM_NCLBUTTONDBLCLK] and self._isHoverMaxBtn():
e = QMouseEvent(QEvent.MouseButtonPress, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
QApplication.sendEvent(self.titleBar.maxBtn, e)
return True, 0
elif msg.message in [win32con.WM_NCLBUTTONUP, win32con.WM_NCRBUTTONUP] and self._isHoverMaxBtn():
e = QMouseEvent(QEvent.MouseButtonRelease, QPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
QApplication.sendEvent(self.titleBar.maxBtn, e)
return super().nativeEvent(eventType, message)
def _isHoverMaxBtn(self):
pos = QCursor.pos() - self.geometry().topLeft() - self.titleBar.pos()
return self.titleBar.childAt(pos) is self.titleBar.maxBtn
\ No newline at end of file
...@@ -7,7 +7,6 @@ from PyQt5.QtWidgets import QApplication, QHBoxLayout, QFrame, QWidget ...@@ -7,7 +7,6 @@ from PyQt5.QtWidgets import QApplication, QHBoxLayout, QFrame, QWidget
from qfluentwidgets import (NavigationInterface, NavigationItemPosition, MessageBox, from qfluentwidgets import (NavigationInterface, NavigationItemPosition, MessageBox,
isDarkTheme, PopUpAniStackedWidget, qrouter) isDarkTheme, PopUpAniStackedWidget, qrouter)
from qfluentwidgets import FluentIcon as FIF from qfluentwidgets import FluentIcon as FIF
from qframelesswindow import FramelessWindow
from .title_bar import CustomTitleBar from .title_bar import CustomTitleBar
from .gallery_interface import GalleryInterface from .gallery_interface import GalleryInterface
...@@ -27,6 +26,7 @@ from .text_interface import TextInterface ...@@ -27,6 +26,7 @@ from .text_interface import TextInterface
from .view_interface import ViewInterface from .view_interface import ViewInterface
from ..common.config import SUPPORT_URL from ..common.config import SUPPORT_URL
from ..components.avatar_widget import AvatarWidget from ..components.avatar_widget import AvatarWidget
from ..components.frameless_window import FramelessWindow
from ..common.icon import Icon from ..common.icon import Icon
from ..common.signal_bus import signalBus from ..common.signal_bus import signalBus
from ..common.style_sheet import StyleSheet from ..common.style_sheet import StyleSheet
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册