Como puedo animar multiple coordenadas con QPropertyAnimation?
Publicado por Marc Sala (1 intervención) el 24/11/2021 00:30:50
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.resize(600, 600)
self.c=0
self.lpx=[]
self.lpy=[]
self.lpx.append(40)
self.lpy.append(150)
self.MainWidgets()
def RobotAnimation(self):
self.n=0
print(self.lpx)
print(self.lpy)
print(self.c)
for self.n in range(0,self.c,1):
print(self.n)
self.anim = QPropertyAnimation(self.robot, b"pos")
self.anim.setStartValue(QPoint(self.lpx[0],self.lpy[0]))
self.anim.setEndValue(QPoint(self.lpx[1],self.lpy[1]))
self.anim.setEndValue(QPoint(self.lpx[2],self.lpy[2]))
self.anim.setDuration(5000)
self.anim.start()
def MainWidgets(self):
self.formLayoutWidgets = QFormLayout()
self.PxLineEdit = QLineEdit(self)
self.PyLineEdit = QLineEdit(self)
self.AcceptButton=QPushButton("Accept")
self.SimulateButton=QPushButton("Simulate")
self.robot=QWidget(self)
self.robot.setStyleSheet("border-width:5px; border-color:black; border-style:solid; background-color:white; border-radius:50px;")
self.robot.resize(100, 100)
self.robot.move(40,150)
self.formLayoutWidgets.addRow("Px=", self.PxLineEdit)
self.formLayoutWidgets.addRow("Py=", self.PyLineEdit)
self.formLayoutWidgets.addRow(self.AcceptButton)
self.formLayoutWidgets.addRow(self.SimulateButton)
self.PxLineEdit.setPlaceholderText('0')
self.PyLineEdit.setPlaceholderText('0')
intValidator = QIntValidator(self)
self.PxLineEdit.setValidator(intValidator)
self.PyLineEdit.setValidator(intValidator)
self.PyLineEdit.returnPressed.connect(lambda: self.Getxy())
self.AcceptButton.clicked.connect(lambda: self.Getxy())
self.SimulateButton.clicked.connect(lambda: self.RobotAnimation())
self.setLayout(self.formLayoutWidgets)
def Getxy(self):
self.c=self.c+1
self.x=self.PxLineEdit.text()
self.y=self.PyLineEdit.text()
self.lpx.append(int(self.x))
self.lpy.append(int(self.y))
app=QApplication([])
Application=MainWindow()
Application.show()
app.exec_()
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.resize(600, 600)
self.c=0
self.lpx=[]
self.lpy=[]
self.lpx.append(40)
self.lpy.append(150)
self.MainWidgets()
def RobotAnimation(self):
self.n=0
print(self.lpx)
print(self.lpy)
print(self.c)
for self.n in range(0,self.c,1):
print(self.n)
self.anim = QPropertyAnimation(self.robot, b"pos")
self.anim.setStartValue(QPoint(self.lpx[0],self.lpy[0]))
self.anim.setEndValue(QPoint(self.lpx[1],self.lpy[1]))
self.anim.setEndValue(QPoint(self.lpx[2],self.lpy[2]))
self.anim.setDuration(5000)
self.anim.start()
def MainWidgets(self):
self.formLayoutWidgets = QFormLayout()
self.PxLineEdit = QLineEdit(self)
self.PyLineEdit = QLineEdit(self)
self.AcceptButton=QPushButton("Accept")
self.SimulateButton=QPushButton("Simulate")
self.robot=QWidget(self)
self.robot.setStyleSheet("border-width:5px; border-color:black; border-style:solid; background-color:white; border-radius:50px;")
self.robot.resize(100, 100)
self.robot.move(40,150)
self.formLayoutWidgets.addRow("Px=", self.PxLineEdit)
self.formLayoutWidgets.addRow("Py=", self.PyLineEdit)
self.formLayoutWidgets.addRow(self.AcceptButton)
self.formLayoutWidgets.addRow(self.SimulateButton)
self.PxLineEdit.setPlaceholderText('0')
self.PyLineEdit.setPlaceholderText('0')
intValidator = QIntValidator(self)
self.PxLineEdit.setValidator(intValidator)
self.PyLineEdit.setValidator(intValidator)
self.PyLineEdit.returnPressed.connect(lambda: self.Getxy())
self.AcceptButton.clicked.connect(lambda: self.Getxy())
self.SimulateButton.clicked.connect(lambda: self.RobotAnimation())
self.setLayout(self.formLayoutWidgets)
def Getxy(self):
self.c=self.c+1
self.x=self.PxLineEdit.text()
self.y=self.PyLineEdit.text()
self.lpx.append(int(self.x))
self.lpy.append(int(self.y))
app=QApplication([])
Application=MainWindow()
Application.show()
app.exec_()
Valora esta pregunta


0