from PyQt5.Qt import *
import sys
class Btn(QPushButton):
def hitButton(self, point):
print(point.x())
if point.x()>self.width()/2:
return True
return False
class CircleButton(QPushButton):
def hitButton(self, point):
#圆心
x,y=self.width()/2,self.height()/2
hit_x=point.x()
hit_y=point.y()
#距离(x2-x1)平方+(y1-y2)平方 再开平方
import math
distance=math.sqrt(math.pow(hit_x-x,2)+math.pow(hit_y-y,2))
if distance<self.width()/2:
return True
return False
def paintEvent(self, evt):
super().paintEvent(evt)
painter=QPainter(self)
painter.setPen(QPen(QColor(23,43,255),2))
painter.drawEllipse(0,0,self.width(),self.height())
# painter.drawText(self.width()/2-20,self.height()/2,self.text())
按钮有效区域
最新推荐文章于 2024-08-15 01:55:01 发布