Solved Custom EasingCurve
-
Hi,
While there are workarounds for this problem, I'm just curious on how this works. I was playing around trying to pass a custom easing curve. I can't find any examples online how to implement it. From the looks of it,
qreal myEasingFunction(qreal progress);
is the function signature I have to use. However, when I try to set the types and etc, I feel like a dog trying to catch his tail. For the timeline, for setEasingCurve, I'm supposed to pass in QEasingFunction::Custom, which is really a static equation. However, to make it return a custom type is tricky. I'm supposed to pass in the easing function into setCustomType, but the ideas that I tried don't work.
Thanks
-
Hi
This compiles and runs like expected but its not what u mean ?#include <QEasingCurve>
qreal myEasingFunction(qreal progress) {
return progress*0.5;
}-- (in button click)
QEasingCurve c;
c.setCustomType(myEasingFunction);
for(qreal t = 0.0; t < 1.0; t += 0.1) {
qDebug() << ">" << t << " is " << c.valueForProgress(t);
} -
@mrjj said in Custom EasingCurve:
QEasingCurve c;
c.setCustomType(myEasingFunction);
for(qreal t = 0.0; t < 1.0; t += 0.1) {
qDebug() << ">" << t << " is " << c.valueForProgress(t);
}Hi mrjj,
Thanks for your response. That was something that I tried initially, but I was unable to get it to compile.
I get this compile-time error:
C:\Users\chris\Documents\Qt Projects\untitled6\mainwindow.cpp:26: error: C3867: 'MainWindow::myEasingFunction': non-standard syntax; use '&' to create a pointer to member.
I know, somewhat confusing. But what it is trying to say, is that I need myEasingFunction() instead of myEasingFunction. And even with myEasingFunction(), I still need to pass in a variable. I'm thinking your code sample has no errors, but maybe there is something small that I need to do. Because, myEasingFunction is a pointer to a function and I have seen examples of such implementation.
-
Hi
It expects a normal function pointer.
Not a member function pointer as you tried.
its not the same as a standalone function pointer (unless static)
as it requires an object to be activated.so
void myfunc()
is not the same
as
void mainwindow::myfunc()in this regards.
-
I'm going to send you a simplified screenshot. Please hold.
-
-
Hi
yes
You cannot use a member function.
It must be free (global) non member function as in my sample. -
Okay, reading your comment, I got rid of MainWindow part, but still something else is causing that error.
-
just put it above like
qreal myEasingFunction(qreal progress) { return progress*0.5; }
... use it here
then it should just work.
-
You're really good. I was just looking at my code and realized that I'm using C++, not C#, so you must have the signature declared beforehand and I came back to the forum with you pointing that out.
Silly me!
Thanks Qt Champion and you were a lot of help like always. I'm sure others will find this useful.
-
Yep, has to see it before use :)
Also just as a note
You can use a member functions, if its declared with static (in the class .h )
but a normal function is better in my book.