实现python 窗口隐藏边框和背景透明
按下鼠标,随意拖动窗口
from PySide6.QtWidgets import QApplication,QMainWindow,QWidget
from PySide6.QtCore import Qt
import sys
from ui_main import Ui_Mainwondow
class MainWin(QMainWindow):
def __init__(self) -> None:
super().__init__()
self.ui = Ui_Mainwondow()
self.ui.setupUi(self)
self.setWindowFlags(Qt.FramelessWindowHint) # 隐藏边框
self.setAttribute(Qt.WA_TranslucentBackground) # 背景透明
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.drag_position = event.globalPos() - self.frameGeometry().topLeft()
event.accept()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
self.move(event.globalPos() - self.drag_position)
event.accept()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWin()
window.show()
sys.exit(app.exec())