1 Star 0 Fork 1

OpenCG/smart_qtwidgets

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
frameless_movable_widget.py 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
sheen 提交于 2021-08-04 14:53 . 更新
#!/usr/bin/env python
# -*- coding: utf8 -*-
from qtpy import QtWidgets, QtCore, QtWidgets
class FramelessMovableWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super(FramelessMovableWidget, self).__init__(parent)
# 初始化参数
self._move = False
self._parent = parent
# 无边框透明
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowSystemMenuHint)
# self.setAttribute(Qt.WA_TranslucentBackground)
self.setWindowOpacity(0)
self.setSizePolicy(QtWidgets.QSizePolicy.Expanding,QtWidgets.QSizePolicy.Fixed)
self.maxNormal=False
def mousePressEvent(self,event):
if event.button() == QtCore.Qt.LeftButton:
self._move = True
self._src_pos = event.globalPos()
self._parent_pos = self._parent.pos()
def mouseReleaseEvent(self, event):
self._move = False
def mouseMoveEvent(self,event):
if self._move:
offset = event.globalPos() - self._src_pos
self._parent.move( self._parent_pos + offset)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/tdercg/smart_qtwidgets.git
git@gitee.com:tdercg/smart_qtwidgets.git
tdercg
smart_qtwidgets
smart_qtwidgets
master

搜索帮助