PyQt5 无边框(无frame)拖拽与缩放后,原界面按钮无法点击问题

倾城一少 2017-11-09 03:07:03
RT,按照下面的代码实现了界面的拖拽和缩放,但是界面的功能按键不能用了,好像一直在def nativeEvent(self,eventType,message)事件中循环,请教大家怎么解决。
下面是代码:
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtCore import Qt
import sip
from ctypes.wintypes import *
from PyQt5.QtWidgets import (QWidget, QLabel,
QComboBox, QApplication)

#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)
self.initUI()

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 = 1,20
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

def initUI(self):
self.lb1 = QLabel("Ubuntu", self)
combo = QComboBox(self)
combo.addItem("Ubuntu")
combo.addItem("Mandriva")
combo.addItem("Fedora")
combo.addItem("Arch")
combo.addItem("Gentoo")

combo.move(50, 50)
self.lb1.move(50, 150)

combo.activated[str].connect(self.onActivated)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('QComboBox')
self.show()

def onActivated(self, text):
self.lb1.setText(text)
self.lb1.adjustSize()





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

app.exec_()

...全文
273 回复 点赞 打赏 收藏 举报
写回复
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
脚本语言
加入

3.7w+

社区成员

JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
申请成为版主
帖子事件
创建了帖子
2017-11-09 03:07
社区公告

CSDN 脚本语言社区接受专栏投稿(专栏会在顶部创建专属你的栏目),投稿需满足以下要求:

  • 脚本语言技术相关;
  • 文章持续更新,保持活跃;
  • 内容清晰明了,干货为主;
  • 文章排版有序,有条有理。

本社区开通招聘专栏,发布招聘信息请联系版主,发布者需要保证招聘信息真实有效,CSDN 平台和版主不对招聘内容负责!

联系方式:私聊版主、发送邮件、QQ联系等均可: