Issue
I am learning Qt and think animating button things are important. I am trying to create my custom QPushButton class which reimplement mouse enter & leave event and use qt animation framework. QPropertyAnimation
QPropertyAnimation(QObject * target, const QByteArray & propertyName, QObject * parent = 0)
So if i want to animate its size, i can use "geometry" as propertyName
but it confuses me when i wanna change both text color and background color too... what should i put as propertyName
? been searching anywhere but didn't find any documentations about what property i could animate and how it is named in propertyName
constructor argument.
Expected answer would be all possible parameter Like "geometry" in QtCore.QPropertyAnimation(self,"geometry")
(pyqt4/pyside)
I use PyQt4 but I can use PySide & Qt4.8 C++ too so answer in any of those libraries will be okay (gonna learn them all)
Edit:
I found this one using "color" and it changes whole pushbutton color (background color), still don't know how to get text visible & animate the text-color
Solution
Text color and background color are not Qt properties. So you can't animate them using QPropertyAnimation
.
You can find the list of QWidget
properties in the appropriate section of the official documentation: http://doc.qt.io/qt-4.8/qwidget.html
If you want to dynamically change some arbitrary attributes like text color, you can launch a QTimer
and perform necessary operations in a slot connected to the timer timeout
signal.
--upd--
In C++ Qt you can't animate 'color' property because there is no such property. If you try to do it, you'll get the following warning in the console:
QPropertyAnimation: you're trying to animate a non-existing property color of your QObject
As a subclass of
QVariantAnimation
, QPropertyAnimation
does not support all QVariant
property types. Supported types are listed in the doc:
Not all QVariant types are supported. Below is a list of currently supported QVariant types:
Int
UInt
Double
Float
QLine
QLineF
QPoint
QPointF
QSize
QSizeF
QRect
QRectF
QColor
If you want to animate a property of some other type, you should register an interpolator function for it:
QVariant cursorInterpolator(const QCursor &start, const QCursor &end, qreal progress)
{
...
return QCursor(...);
}
...
qRegisterAnimationInterpolator<QCursor>(cursorInterpolator);
Answered By - hank
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.