python--pyQt 基础框架代码 pyside6

整个框架

import sys
from PySide6 import QtWidgets, QtCore, QtGui
from PySide6.QtCore import Qt, QRect
from PySide6.QtGui import QColor, QEnterEvent
from PySide6.QtWidgets import QApplication, QDialog, QMainWindow, QGraphicsDropShadowEffect

import yiqi_ui



class MainWindow(QMainWindow,yiqi_ui.Ui_MainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.win = yiqi_ui.Ui_MainWindow()
        self.win.setupUi(self)

        self.setWindowFlag(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)

        self.show()

    # 拖动
    def mousePressEvent(self, event):
        if event.button() == QtCore.Qt.LeftButton and self.isMaximized() == False:
            self.m_flag = True
            self.m_Position = event.globalPos() - self.pos()  # 获取鼠标相对窗口的位置
            event.accept()
            self.setCursor(QtGui.QCursor(QtCore.Qt.OpenHandCursor))  # 更改鼠标图标

    def mouseMoveEvent(self, mouse_event):
        if QtCore.Qt.LeftButton and self.m_flag:
            self.move(mouse_event.globalPos() - self.m_Position)  # 更改窗口位置
            mouse_event.accept()

    def mouseReleaseEvent(self, mouse_event):
        self.m_flag = False
        self.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))


if __name__ == '__main__':
    app = QApplication(sys.argv)  # 初始化
    win = MainWindow()  # 初始化界面并展示
    win.show()
    app.exec()

你可能感兴趣的:(pyside6,python,pyqt,开发语言)