本文整理汇总了Python中PyQt5.QtCore.QPoint.y方法的典型用法代码示例。如果您正苦于以下问题:Python QPoint.y方法的具体用法?Python QPoint.y怎么用?Python QPoint.y使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QPoint
的用法示例。
在下文中一共展示了QPoint.y方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Winform
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
class Winform(QWidget):
def __init__(self,parent=None):
super(Winform,self).__init__(parent)
self.setWindowTitle("双缓冲绘图例子")
self.pix = QPixmap()
self.lastPoint = QPoint()
self.endPoint = QPoint()
# 辅助画布
self.tempPix = QPixmap()
# 标志是否正在绘图
self.isDrawing = False
self.initUi()
def initUi(self):
#窗口大小设置为600*500
self.resize(600, 500);
# 画布大小为400*400,背景为白色
self.pix = QPixmap(400, 400);
self.pix.fill(Qt.white);
def paintEvent(self,event):
painter = QPainter(self)
x = self.lastPoint.x()
y = self.lastPoint.y()
w = self.endPoint.x() - x
h = self.endPoint.y() - y
# 如果正在绘图,就在辅助画布上绘制
if self.isDrawing :
# 将以前pix中的内容复制到tempPix中,保证以前的内容不消失
self.tempPix = self.pix
pp = QPainter( self.tempPix)
pp.drawRect(x,y,w,h)
painter.drawPixmap(0, 0, self.tempPix)
else :
pp = QPainter(self.pix )
pp.drawRect(x, y, w, h)
painter.drawPixmap(0, 0, self.pix)
def mousePressEvent(self, event) :
# 鼠标左键按下
if event.button() == Qt.LeftButton :
self.lastPoint = event.pos()
self.endPoint = self.lastPoint
self.isDrawing = True
def mouseReleaseEvent( self, event):
# 鼠标左键释放
if event.button() == Qt.LeftButton :
self.endPoint = event.pos()
#进行重新绘制
self.update()
self.isDrawing = False
示例2: Text
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
class Bullet:
"""Bullet contains:
1 StartPosition
2 EndPosition
3 Color
4 Text( A String)
5 Duration
It uses the "window" to draw it selft
"""
#这个叫做 类的属性
Count=0# 通过类名Bullet.bullet访问,就是一个静态变量
Height=GLOBAL.BULLETFONTSIZE+6 #一个Bullet占用的像素高度
def __init__(self, Text, Color,Duration):
Bullet.Count+=1
#这个里面self给定的内容则只属于当前对象
self.Text=Text
self.Color=Color
self.Duration=Duration*1000 #单位是毫秒,输入的是秒
self.IsExpired=False
"""this method must be called when this
bullet is ready to shoot at the first time
"""
def prepare(self):
self.elapsedTimer=QElapsedTimer()
self.elapsedTimer.start() #start time
self.StartPosition=QPoint(GLOBAL.WINDOWWIDTH+random.randrange(200,500,20),\
(Bullet.Height+(Bullet.Count%(GLOBAL.WINDOWHEIGHT//Bullet.Height))*Bullet.Height))
self.EndPosition=QPoint(-2000 ,self.StartPosition.y())
"""Draw this bullet at position x,y ,use painter
Returns True indicates this bullet is out of screen
"""
def draw(self,painter):
ratio=self.elapsedTimer.elapsed()/self.Duration
if(ratio>0.9):
self.IsExpired=True
# pos=ratio*self.EndPosition+(1-ratio)*self.StartPosition
pos=QPoint(ratio*self.EndPosition.x()+(1-ratio)*self.StartPosition.x(),self.StartPosition.y())
#这里需要插入绘制字体阴影的代码
#
# font.setFixedPitch(True)
# painter.setFont(font)
painter.save()
painter.drawText(pos+QPoint(2,2),self.Text)
painter.setPen(QPen(self.Color))
painter.drawText(pos,self.Text)
painter.restore()
# def __del__(self):
# Count-=1
# print ("刚刚自动Delete了一个bullet\n")
示例3: draw_item
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def draw_item(self, face, painter):
is_draw = True
if self.is_clipping:
is_draw = self.sphere.is_face_visible(face)
if is_draw:
polygon = QPolygon()
for index, point_index in enumerate(face):
p1_x = int(self.sphere.geom.points[face[index-1]][0])
p1_y = int(self.sphere.geom.points[face[index-1]][1])
p1_z = int(self.sphere.geom.points[face[index-1]][2])
p2_x = int(self.sphere.geom.points[point_index][0])
p2_y = int(self.sphere.geom.points[point_index][1])
p2_z = int(self.sphere.geom.points[point_index][2])
if self.sphere.projection_name == "front":
# Фронтальная проекция (вид спереди) -> z = 0
real_p1 = QPoint(p1_x, p1_y)
real_p2 = QPoint(p2_x, p2_y)
elif self.sphere.projection_name == "horizontal":
# Горизонтальная проекция (вид сверху) -> y = 0
real_p1 = QPoint(p1_x, p1_z)
real_p2 = QPoint(p2_x, p2_z)
elif self.sphere.projection_name == "profile":
# Профильная проекция (вид сбоку) -> x = 0
real_p1 = QPoint(p1_y, p1_z)
real_p2 = QPoint(p2_y, p2_z)
else:
real_p1 = QPoint(p1_x, p1_y)
real_p2 = QPoint(p2_x, p2_y)
# Точки для проволочного рисования
real_p1.setX(self.width()/2 + real_p1.x())
real_p1.setY(self.height()/2 - real_p1.y())
real_p2.setX(self.width()/2 + real_p2.x())
real_p2.setY(self.height()/2 - real_p2.y())
# Полигоны для рисования с цветом
polygon.append(real_p1)
polygon.append(real_p2)
if not self.is_light:
painter.drawLine(real_p1, real_p2)
if self.is_light:
painter.setBrush(self.sphere.get_face_light(face, self.faces_color))
painter.drawPolygon(polygon)
示例4: CanvasView
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
class CanvasView(QtCanvasView):
itemClickedSignal = pyqtSignal(QtCanvasItem)
itemMovedSignal = pyqtSignal(QtCanvasItem)
def __init__(self, arg1=None, arg2=None):
if type(arg1)==QtCanvas:
super(CanvasView, self).__init__(arg1, arg2)
else:
super(CanvasView, self).__init__(arg1)
self.moving = QtCanvasItem(None)
self.moving_start = QPoint()
def contentsMousePressEvent(self, event):
self.handleMouseClickEvent(event)
def contentsMouseDoubleClickEvent(self, event):
self.handleMouseClickEvent(event)
def handleMouseClickEvent(self, event):
p = self.inverseWorldMatrix().map(event.pos())
l = self.canvas().collisions(p)
self.moving = QtCanvasItem(None)
if (not l.isEmpty()):
self.moving = l.first()
self.moving_start = p
self.itemClickedSignal.emit(self.moving)
def contentsMouseMoveEvent(self, event):
if (self.moving):
p = self.inverseWorldMatrix().map(event.pos())
self.moving.moveBy(p.x() - self.moving_start.x(), p.y() - self.moving_start.y())
self.moving_start = p
self.canvas().update()
self.itemMovedSignal.emit(self.moving)
示例5: click
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def click():
window_name = get_window_name()
query_value = get_query_value()
automation_type = get_query_automation_type()
widget = find_widget(window_name, query_value, automation_type)
if widget is None:
return {}
if isinstance(widget, QWidget):
clicker.click_on(widget)
return get_widget_json(widget)
if isinstance(widget, QQuickItem):
pointf = widget.mapToScene(QPointF(0.0, 0.0))
x = pointf.x()
y = pointf.y()
x += qml_method_or_default(widget, "width", 0.0) / 2.0
y += qml_method_or_default(widget, "height", 0.0) / 2.0
window_name = get_window_name()
root_widget = get_root_widget(window_name)
point = QPoint(x,y)
quick_widget = root_widget.childAt(point.x(), point.y())
clicker.click_on(quick_widget, point)
return get_widget_json(widget)
return {}
示例6: Winform
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
class Winform(QWidget):
def __init__(self,parent=None):
super(Winform,self).__init__(parent)
self.setWindowTitle("绘制矩形图形例子")
self.pix = QPixmap()
self.lastPoint = QPoint()
self.endPoint = QPoint()
self.initUi()
def initUi(self):
#窗口大小设置为600*500
self.resize(600, 500)
# 画布大小为400*400,背景为白色
self.pix = QPixmap(400, 400)
self.pix.fill(Qt.white)
def paintEvent(self,event):
painter = QPainter(self)
x = self.lastPoint.x()
y = self.lastPoint.y()
w = self.endPoint.x() - x
h = self.endPoint.y() - y
pp = QPainter(self.pix)
pp.drawRect(x, y, w, h)
painter.drawPixmap(0, 0, self.pix)
def mousePressEvent(self, event) :
# 鼠标左键按下
if event.button() == Qt.LeftButton :
self.lastPoint = event.pos()
self.endPoint = self.lastPoint
def mouseMoveEvent(self, event):
# 鼠标左键按下的同时移动鼠标
if event.buttons() and Qt.LeftButton :
self.endPoint = event.pos()
#进行重新绘制
self.update()
def mouseReleaseEvent( self, event):
# 鼠标左键释放
if event.button() == Qt.LeftButton :
self.endPoint = event.pos()
#进行重新绘制
self.update()
示例7: snapToGrid
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def snapToGrid(self, position):
#Return position of closest grid point
gridSizeX = 40
gridSizeY = 20
curPos = QPoint(position.x(), position.y())
gridPos = QPoint(round(curPos.x() / gridSizeX) * gridSizeX, round(curPos.y() / gridSizeY) * gridSizeY)
return gridPos
示例8: get_linear_gradient
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def get_linear_gradient(self):
fontHeight = self.fontMetrics().height()
startPoint = QPoint(self.rect().x(), self.rect().y() + 0.5 * (self.rect().height() - fontHeight))
endPoint = QPoint(startPoint.x(), startPoint.y() + fontHeight)
linear = QLinearGradient(startPoint, endPoint)
colorCounts = len(self.colors)
for i in range(colorCounts):
linear.setColorAt(0.2 + i / colorCounts, self.colors[i])
return linear
示例9: kineticMove
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def kineticMove(self, oldx, oldy, newx, newy ):
"""Start a kinetic move from (oldx, oldy) to (newx, newy)"""
if newx == oldx and newy == oldy:
return
speed = QPoint(0,0)
# solve speed*(speed+1)/2 = delta to ensure 1+2+3+...+speed is as close as possible under delta..
speed.setX((sqrt(1+8*abs(newx-oldx))-1)/2)
speed.setY((sqrt(1+8*abs(newy-oldy))-1)/2)
# compute the amount of displacement still needed because we're dealing with integer values.
diff = QPoint(0,0)
diff.setX((speed.x() * (speed.x() + 1) // 2) - abs(newx - oldx))
diff.setY((speed.y() * (speed.y() + 1) // 2) - abs(newy - oldy))
# Since this function is called for exact moves (not free scrolling)
# limit the kinetic time to 2 seconds, which means 100 ticks, 5050 pixels.
if speed.y() > 100:
speed.setY(100)
diff.setY(-abs(newy-oldy) + 5050)
# Although it is less likely to go beyond that limit for horizontal scrolling,
# do it for x as well.
if speed.x() > 100:
speed.setX(100)
diff.setX(-abs(newx-oldx) + 5050)
# move left or right, up or down
if newx > oldx :
speed.setX(-speed.x())
diff.setX(-diff.x())
if newy > oldy :
speed.setY(-speed.y())
diff.setY(-diff.y())
# move immediately by the step that cannot be handled by kinetic scrolling.
# By construction that step is smaller that the initial speed value.
self.fastScrollBy(diff)
self.kineticStart(speed)
示例10: wave
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def wave(self):
# print(points[0][0] ,'<', points[1][0], 'and', points[0][1], '>', points[1][1])
t = self.machine.getTransition(self.t_active)
init = QPoint(t.getOrig()[0], t.getOrig()[1])
end = QPoint(t.getDest()[0], t.getDest()[1])
angle = t.getAngle()
print('processing transition', t.id, t.orig, t.dest)
while t.isActive():
self.pts = [[init.x(), init.y()], [end.x(), end.y()]]
if self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
while self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
self.sumPoint(angle)
elif self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
while self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
self.sumPoint(angle)
elif self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
while self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
self.sumPoint(angle)
elif self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
while self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
self.sumPoint(angle)
示例11: wave
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def wave(self):
t = self.machine.getActiveTransition()
if t != None:
init = QPoint(t.getOrig()[0], t.getOrig()[1])
end = QPoint(t.getDest()[0], t.getDest()[1])
angle = t.getAngle()
#print('processing transition', t.id, t.orig, t.dest)
while t.isActive():
#for i in range(3): #for testing
self.pts = [[init.x(), init.y()], [end.x(), end.y()]]
if self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
while self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
self.sumPoint(angle)
elif self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
while self.pts[0][0] <= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
self.sumPoint(angle)
elif self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
while self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] >= self.pts[1][1]:
self.sumPoint(angle)
elif self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
while self.pts[0][0] >= self.pts[1][0] and self.pts[0][1] <= self.pts[1][1]:
self.sumPoint(angle)
示例12: setOffset
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def setOffset(self, offset):
# Clamp the offset within the offset bounds
newOffset = QPoint(min(self.mOffsetBounds.right(),
max(self.mOffsetBounds.left(), offset.x())),
min(self.mOffsetBounds.bottom(),
max(self.mOffsetBounds.top(), offset.y())))
if (self.mOffset != newOffset):
xChanged = self.mOffset.x() != newOffset.x()
yChanged = self.mOffset.y() != newOffset.y()
self.mOffset = newOffset
if (xChanged):
self.offsetXChanged.emit(self.mOffset.x())
if (yChanged):
self.offsetYChanged.emit(self.mOffset.y())
self.offsetChanged.emit(self.mOffset)
self.update()
示例13: enemyClick
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def enemyClick(self, enemy):
# Opens an info screen on the enemy
if self.parent.gameover == False and enemy.isDead == False:
if self.parent.isTowerSelected == False:
# self.statusBarMessage("Enemy clicked")
self.enemyPopUp = QFrame()
self.enemyPopUp.setGeometry(500, 500, 100, 100)
grid = QGridLayout()
self.enemyPopUp.setLayout(grid)
enemyStats = QLabel("Enemy Stats")
name = QLabel("Name: " + str(enemy.name))
speed = QLabel("Speed: " + str(enemy.speed))
health = QLabel("Health: {:.0f}".format(enemy.health))
pixmap = QLabel()
pixmap.setPixmap(enemy.picture)
vbox = QVBoxLayout()
vbox.addWidget(enemyStats)
vbox.addWidget(name)
vbox.addWidget(speed)
vbox.addWidget(health)
grid.addLayout(vbox, 0, 0)
vbox2 = QVBoxLayout()
vbox2.addWidget(pixmap)
vbox2.addStretch()
doneButton = QPushButton("Done")
vbox2.addWidget(doneButton)
grid.addLayout(vbox2, 0, 1)
location = QPoint(QCursor.pos())
self.enemyPopUp.move(location.x() - 100, location.y())
self.enemyPopUp.show()
doneButton.clicked.connect(self.enemyPopUp.hide)
elif self.parent.gameover == True:
self.statusBarMessage("The game has ended. Stop doing stuff.")
示例14: download
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def download(self):
grab = None
for x in range(self._tilesRect.width()):
for y in range(self._tilesRect.height()):
tp = Point(self._tilesRect.topLeft() + QPoint(x, y))
if tp not in self._tilePixmaps:
grab = QPoint(tp)
break
if grab is None:
self._url = QUrl()
return
path = 'http://tile.openstreetmap.org/%d/%d/%d.png' % (self.zoom, grab.x(), grab.y())
self._url = QUrl(path)
request = QNetworkRequest()
request.setUrl(self._url)
request.setRawHeader(b'User-Agent', b'Nokia (PyQt) Graphics Dojo 1.0')
request.setAttribute(QNetworkRequest.User, grab)
self._manager.get(request)
示例15: paintEvent
# 需要导入模块: from PyQt5.QtCore import QPoint [as 别名]
# 或者: from PyQt5.QtCore.QPoint import y [as 别名]
def paintEvent(self, event):
painter = QPainter(self)
painter.setPen(self.pen)
painter.setBrush(self.brush)
if self.antialiased:
painter.setRenderHint(QPainter.Antialiasing)
angle_step = 360 / self.n_states
painter.save() #Save_1. Save the state of the system (push matrix)
painter.translate(self.dist_center.x(), self.dist_center.y()) # go to the center of the render area
painter.rotate(-180) #to start painting from the left side of the circle (clockwise)
#center of the circumference where through we are going to paint our states
x = self.dist_radius * math.cos(0)
y = self.dist_radius * math.sin(0)
for h in range(self.n_states):
rot = angle_step * h # each state is equidistant from the others. We paint them in circles
painter.save() #Save_2
painter.rotate(rot) #now our system is pointing to the next state to be drawn
painter.translate(x,y) #now our origin is in the center of the next state to be drawn
#if the state is active, fill it green
if self.machine.getState(h).isActive():
painter.setBrush(self.greenGradientBrush)
painter.drawEllipse(QPoint(0,0), self.state_radius, self.state_radius) #draw the new state
#global position of transformed coordinates (before any transformation, origin at top-left corner)
gx = painter.worldTransform().map(QPoint(0,0)).x()
gy = painter.worldTransform().map(QPoint(0,0)).y()
self.machine.getState(h).setPos(gx, gy) #store the center of the state without any transformation applied
# text transformation. Our origin is still in the center of the current state
painter.save() #Save_3
painter.rotate(180) #making the text go vertical
painter.rotate(-rot) #undoing the rotation made for painting the state. No the text is horizontal
font = painter.font();
font.setPixelSize(self.state_radius*.4);
painter.setFont(font);
rect = QRect(-self.state_radius, -self.state_radius, self.state_radius*2, self.state_radius*2)
painter.drawText(rect, Qt.AlignCenter, self.machine.getState(h).getName());
painter.restore() #Restore_3
#end text transformation
painter.restore() #Restore_2
painter.restore() #Restore_1. Restore the state of the system (pop matrix)
#drawing transitions. Line between states
painter.save() # Save_4
pptv = QTransform() #Define a new transformation. Needed to rotate the system along other axis than Z
pptv.translate(0, self.height()) #We are now at the bottom-left corner of the screen
pptv.rotate(-180, Qt.XAxis) #Rotate along the X-axis so now we are in a typical cartesian system.
painter.setTransform(pptv) #Apply the transformation
states = self.machine.getStates()
for state in states:
transitions = state.getTransitions()
for transition in transitions:
#get the center of the origin and destination states in our current system state
orig = QPoint(state.getPos()[0], state.getPos()[1])
end = QPoint(self.machine.getState(transition.getStateEnd()).getPos()[0], self.machine.getState(transition.getStateEnd()).getPos()[1])
# get those coordinates without transformation
orig2 = QPoint(painter.worldTransform().map(orig))
end2 = QPoint(painter.worldTransform().map(end))
#get the angle between states centers and the horizon
angle = math.atan2(end2.y() - orig2.y(), end2.x() - orig2.x())
#get the coordinates of the starting point of the transition (it starts in the bound of the state, not in the center)
newX = self.state_radius * math.cos(angle) + orig2.x()
newY = self.state_radius * math.sin(angle) + orig2.y()
#now the transition starts at the border, not in the center
orig2.setX(newX)
orig2.setY(newY)
#same for the destination state
angle2 = math.atan2(orig2.y() - end2.y(), orig2.x() - end2.x())
newX2 = self.state_radius * math.cos(angle2) + end2.x()
newY2 = self.state_radius * math.sin(angle2) + end2.y()
end2.setX(newX2)
end2.setY(newY2)
#draw the line between the origin and destination states
painter.drawLine(orig2, end2)
#get the start and the end of the transition untransformed
init = QPoint(painter.worldTransform().map(orig2))
end = QPoint(painter.worldTransform().map(end2))
#store that info
transition.setOrig(init.x(), init.y())
transition.setDest(end.x(), end.y())
transition.setAngle(angle)
painter.restore() #Restore_4
#.........这里部分代码省略.........