PYQT5 实现 无frame窗口的拖动和放缩

# -*- coding:utf-8 -*-
'''
Created on 2016年12月14日

@author: DXL

Copyright (C) 2004-2019 Shandong Zhaoyuan Software Development Co.,Ltd

'''
import cgitb
cgitb.enable( format='text')
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtCore import Qt 
import sip
from ctypes.wintypes import *

print (help(MSG))
PADDING = 2
UP,DOWN,LEFT,RIGHT,LEFTTOP,LEFTBOTTOM,RIGHTTOP,RIGHTBOTTOM,UNDIRECT = range(9)
HTLEFT = 10
HTRIGHT = 11
HTTOP = 12
HTTOPLEFT = 13
HTTOPRIGHT = 14
HTBOTTOM = 15
HTBOTTOMLEFT = 16
HTBOTTOMRIGHT = 17
HTCAPTION = 2      

class CustomWidget(QWidget):
    def __init__(self,parent=None):
        QWidget.__init__(self,parent)
        self.setWindowFlags(Qt.FramelessWindowHint)

    def isInTitle(self, xPos, yPos):
        return yPos < 30

    def GET_X_LPARAM(self, param):
        return param & 0xffff

    def GET_Y_LPARAM(self, param):
        return param >> 16

    def nativeEvent(self,eventType,message):
        result = 0
        msg2 = ctypes.wintypes.MSG.from_address(message.__int__())
        minV,maxV = 18,22
        if msg2.message == 0x0084:
            print(msg2)
            xPos = self.GET_X_LPARAM(msg2.lParam) - self.frameGeometry().x()
            yPos = self.GET_Y_LPARAM(msg2.lParam) - self.frameGeometry().y()
#             if self.childAt(xPos,yPos) == 0:
#                 result = HTCAPTION
#             else:
#                 return (False,result)
            if(xPos > minV and xPos < maxV):
                result = HTLEFT
            elif(xPos > (self.width() - maxV) and xPos < (self.width() - minV)):
                result = HTRIGHT
            elif(yPos > minV and yPos < maxV):
                result = HTTOP
            elif(yPos > (self.height() - maxV) and yPos < (self.height() - minV)):
                result = HTBOTTOM
            elif(xPos > minV and xPos < maxV and yPos > minV and yPos < maxV):
                result = HTTOPLEFT
            elif(xPos > (self.width() - maxV) and xPos < (self.width() - minV) and yPos > minV and yPos < maxV):
                result = HTTOPRIGHT
            elif(xPos > minV and xPos < maxV and yPos > (self.height() - maxV) and yPos < (self.height() - minV)):
                result = HTBOTTOMLEFT
            elif(xPos > (self.width() - maxV) and xPos < (self.width() - minV) and yPos > (self.height() - maxV) and yPos < (self.height() - minV)):
                result = HTBOTTOMRIGHT
            else:
                result = HTCAPTION
            return (True,result)
        ret= QWidget.nativeEvent(self,eventType,message)
        return ret





if __name__ == '__main__':
    app = QApplication([])
    try:
        w = CustomWidget ()
        w.show()
    except:
        import traceback
        traceback.print_exc()

    app.exec_()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值