- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是这个论坛以及 Python 和 PyQt 的新手。在学习了一些基础知识之后,在尝试使用 Qt 学习动画时,我希望编写一个简单的应用程序,其中通过单击另一个按钮将按钮动画地从屏幕左侧带到某个位置。在这个过程中,我最终编写了这样的代码:
class AppMainUI(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
self.setWindowFlags(QtCore.Qt.Window|QtCore.Qt.FramelessWindowHint)
self.connect(self.pushButton_4, QtCore.SIGNAL("clicked()"), self.onExitClicked)
self.connect(self.pushButton_5, QtCore.SIGNAL("clicked()"), self.animateButtons)
def animateButtons(self):
animation = QtCore.QPropertyAnimation(self.pushButton, "geometry")
animation.setDuration(2)
animation.setStartValue(QtCore.QRect(0, 0, self.pushButton.width(), self.pushButton.height()))
animation.setEndValue(QtCore.QRect(760, 280, self.pushButton.width(), self.pushButton.height()))
animation.setEasingCurve(QtCore.QEasingCurve.OutElastic)
animation.start()
def onExitClicked(self):
sys.exit(0)
App = QtGui.QApplication(sys.argv)
UI = AppMainUI()
UI.show()
App.exec_()
我看到按钮移动到位置 (0, 0),这实际上是我的动画开始位置。我在这里做错了什么吗?
最佳答案
问题是由于垃圾收集器造成的;当使用 animation.start()
语句完成 animateButtons(self)
方法时,animation
对象将被垃圾收集器销毁,因此动画不会发生。
只需在对象名称的开头添加 self
即可:
self.animation = QtCore.QPropertyAnimation(...)
self.animation.setStartValue(...)
...
还要将持续时间增加到至少 1000 毫秒,以便动画变得可见,否则它将执行得太快,以至于您看不到它。
关于python - Qt4 中的 PushButton 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21074628/
我是一名 Python 菜鸟,试图将我通过教程学到的一些东西结合起来;专门用 guizero 制作一个 GUI。 我创建了一个名为 player_name 的 TextBox 对象和一个名为 crea
使用 PyQt,我想创建一个满足这组规则的用户界面: 棋盘由大小为 (s,s) 的二维网格组成,其中 s 为奇数 这个网格的每个小部件都是一个 QtPushButton 当我们初始化 UI 时,除了中
我正在使用一个按钮来记录传入的麦克风声音信号。通常,信号在按下记录按钮后到达有点晚,我记录的输出包含零直到 10 毫秒(之后我收到实际输出)。我正在使用以下 QTimer 函数来设置延迟,但输出是相同
我可以使用 FileSaveDialog1.Dialog.QueryInterface 创建一个按钮,如下所示。如何设置和处理 OnPushButton 单击事件以便我可以响应按钮单击? proced
我是这个论坛以及 Python 和 PyQt 的新手。在学习了一些基础知识之后,在尝试使用 Qt 学习动画时,我希望编写一个简单的应用程序,其中通过单击另一个按钮将按钮动画地从屏幕左侧带到某个位置。在
我开始学习 Qt 和编码。我有一个基本的项目,用于练习目的。 这是我的小 UI 的图片: 请耐心等待,因为我才刚开始使用 cpp。 我希望 QPushButton 在我单击后将此字符串 -> “文本”
我正在尝试创建带有自定义颜色和图像/文本的按钮。添加颜色和图像/文本非常容易,但现在我在垂直对齐方面遇到了问题。 “text-alignment: center”帮助我实现了水平对齐,但在垂直方面却没
我正在构建 2 列按钮,在升级到 GWT 2.4.0 之后,我的点击事件出现了问题。 在电脑上单击按钮后,您必须移动鼠标位置才能触发事件。在 iPad 上,必须再次按下该按钮。 int rows =
这个问题在这里已经有了答案: Python Argument Binders (7 个答案) 关闭 5 个月前。 我是 Python 和 PyQt 的新手,这是我的第一个应用程序。当前,当单击按钮时
这个问题在这里已经有了答案: Passing an argument to a slot (6 个答案) 关闭 7 年前。 我有 n 个按钮,最初都标记为“0”。这些标签,或者说值,会在程序运行的时
尝试在我的代码中继续点击按钮事件,但遇到了一些问题。 AttributeError: 'MyMainWindow' object has no attribute 'pushButton' 似乎 cl
我使用 QListWidget 创建了一个播放列表。现在我想用一个按钮保存这个列表,从今以后我可以创建或删除播放列表。另外,我怎样才能列出已保存/现有的列表。 最佳答案 使用QListWidget::
我正在创建一个程序,需要打开一个表单,然后单击按钮关闭前一个表单。我当前的问题是,当我单击按钮时,新表单显示一毫秒然后消失。 void mainMenu::on_mainLoginB_clicked(
我正在尝试构建一个 QLabel,当我按下 QPushButton 时,我希望它出现;代码很简单: void Mod28::on_pushButton_clicked() {
我有完全相同的problem ,但我将使用 QTableView 小部件。我读了this并且想知道我是否可以覆盖 createEditor 函数以使用例如 QFileDialog 来获取新数据。 如果
我在我的 uitable 中实现了各种 uimenu,但出现了一个非常烦人的行为。 function createUItable h = figure ... uimenu(h
我制作了一个读取文件的程序。我有一个读取行号的组合框:1,6,11,..等。我想例如当在组合框中选择第 1 行并单击按钮时,读取第 1-5 行(或者当第 6 行被选择时,读取第 6-10 行,结束等等
我对 PyQt 还很陌生,我正在开发一个 PyQt4 GUI,它的按钮定义如下: self.buttonFormule11=QtGui.QPushButton(self.centralwidget)
我想要一个 QPushButton,其中图像在鼠标悬停时调整大小。 以下适用于 QToolButton: QToolButton { border: 0px; } QToolButton:ho
当单击对话框中的“按钮”时,我想切换回原来的主窗口。我尝试了以下方法,它使 MainWindow 的拷贝可见,但我无法在其中编辑任何内容。请帮忙。 这是MainWindow.h #ifndef MAI
我是一名优秀的程序员,十分优秀!