Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Custom EasingCurve
Forum Updated to NodeBB v4.3 + New Features

Custom EasingCurve

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ChrisW
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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);
      }

      C 1 Reply Last reply
      4
      • mrjjM mrjj

        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);
        }

        C Offline
        C Offline
        ChrisW
        wrote on last edited by
        #3

        @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.

        mrjjM 1 Reply Last reply
        0
        • C ChrisW

          @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.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @ChrisW

          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.

          C 3 Replies Last reply
          2
          • mrjjM mrjj

            @ChrisW

            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.

            C Offline
            C Offline
            ChrisW
            wrote on last edited by
            #5

            @mrjj

            I'm going to send you a simplified screenshot. Please hold.

            1 Reply Last reply
            0
            • mrjjM mrjj

              @ChrisW

              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.

              C Offline
              C Offline
              ChrisW
              wrote on last edited by
              #6

              @mrjj

              0_1518598472240_Capture.PNG

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                Hi
                yes
                You cannot use a member function.
                It must be free (global) non member function as in my sample.

                1 Reply Last reply
                2
                • mrjjM mrjj

                  @ChrisW

                  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.

                  C Offline
                  C Offline
                  ChrisW
                  wrote on last edited by
                  #8

                  @mrjj

                  Okay, reading your comment, I got rid of MainWindow part, but still something else is causing that error.

                  mrjjM 1 Reply Last reply
                  0
                  • C ChrisW

                    @mrjj

                    Okay, reading your comment, I got rid of MainWindow part, but still something else is causing that error.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @ChrisW

                    just put it above like

                    qreal myEasingFunction(qreal progress) {
                    return progress*0.5;
                    }
                    

                    ... use it here

                    then it should just work.

                    C 1 Reply Last reply
                    3
                    • mrjjM mrjj

                      @ChrisW

                      just put it above like

                      qreal myEasingFunction(qreal progress) {
                      return progress*0.5;
                      }
                      

                      ... use it here

                      then it should just work.

                      C Offline
                      C Offline
                      ChrisW
                      wrote on last edited by
                      #10

                      @mrjj

                      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.

                      1 Reply Last reply
                      1
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved