如何在 qt 中对 QPushButton 的背景颜色进行动画处理
How to animate the background color of a QPushButton in qt?
我做了一切[直到我知道的]来动画按钮的背景颜色,但我做不到。以下是我的尝试之一:
# I set the style of the button by setstylesheet()
animation = QPropertyAnimation(btn, "style",btn)
animation.setDuration(1000)
animation.setStartValue(QStyle("background-color:blue"))
animation.setEndValue(QStyle("background-color:red"))
animation.start()
但以下代码显示以下错误:
animation.setStartValue(QStyle("background-color:blue"))TypeError: PyQt4.QtGui.QStyle 表示一个C++抽象类,无法实例化
我还尝试设置调色板:
color = install_btn.palette()
color.setColor(QPalette.Base,QColor(72, 152, 219))
install_btn.setAutoFillBackground(True)
install_btn.setPalette(color)
然后我没有在上面的动画值中QStyle
,我写了QColor(r,g,b)
但这也不起作用,它说:
QPropertyAnimation:您正在尝试对 QObject 的不存在的属性样式进行动画处理
请用您知道的任何语言(C++或Python)帮助我。但我使用Python。
谢谢是特别的
C++,Qt5,但可以在Qt4中工作
QGraphicsColorizeEffect *eEffect= new QGraphicsColorizeEffect(btn);
btn->setGraphicsEffect(eEffect);
QPropertyAnimation *paAnimation = new QPropertyAnimation(eEffect,"color");
paAnimation->setStartValue(QColor(Qt::blue));
paAnimation->setEndValue(QColor(Qt::red));
paAnimation->setDuration(1000);
paAnimation->start();
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 如何在内核C++中使用1920x1080x16M图形或类似的16M颜色?(VGA)
- 如何在24位SDL_Surface上设置像素的颜色
- 如何从SDL_Surface获取特定像素的颜色
- 使用 GLUT 使用键停止动画?
- 使用对象数组对 SFML 进行动画处理
- (SFML)按下键时,播放器构造函数未使用正确的动画进行更新
- 列表视图更改选择颜色
- GtkTreeView 交替行颜色
- dx11 渲染到纹理仅显示透明颜色
- 如何减慢从 BVH 文件读取的 opengl 动画?
- 使用 OpenGL 4.5 更改所选顶点的颜色
- 为什么我的 LEGACY OPENGL 颜色反转了?
- 双击更改 mfc 中列表控件中的行的颜色
- 如何检测是否在缓冲绘画动画中绘制最后一帧?
- 使用动画更改Qwidget的边框颜色
- QTableview单元格的值更新后,如何及时对它的颜色进行动画处理?
- 如何在 qt 中对 QPushButton 的背景颜色进行动画处理
- 单击按钮后对QML矩形的颜色设置动画