Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QAnimations: what's the best way to print flippable cards?
Qt 6.12 LTS is out! See what's new in the release blog

[Solved] QAnimations: what's the best way to print flippable cards?

Scheduled Pinned Locked Moved General and Desktop
38 Posts 3 Posters 35.4k Views 3 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Are you looking for something like described in this thread ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    P 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      Are you looking for something like described in this thread ?

      P Offline
      P Offline
      Pippin
      wrote on last edited by
      #3

      @SGaist Yes, although the OP didn't seem to be using animations.

      My understanding of Qt animations is: you specify the location of the object you want to move at t=0, the location of the destination of that object, the duration of the movement, and Qt will draw everything for you. Keeping that in mind, I'm asking what I should do if I want to progressively scale (horizontally for example) an object from 1 to -1, and change its image halfway when it is scaled to 0 (so that it does look like that object has been flipped).

      Not sure if the above was clear, I can try again if I'm asked.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pippin
        wrote on last edited by
        #4

        Nobody has ever come across my problem before? Nobody has ever tried to flip 2D animations?

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pippin
          wrote on last edited by Pippin
          #5

          Well, since I get no reply, I suppose that there is no obvious answer.

          I think I'll try to use QSequentialAnimationGroups whenever I need to flip a card: a first animation that scales the (face-up) card from 1 to 0, and a second animation that scales the (face-down) card from 0 to 1. The QPixmap of the first animation would be different than the QPixmap of the second one. Hopefully that will work and look natural.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #6

            Hi,

            Please, practice some patience, allow 24 to 48 hours before bumping your own thread. This forum is community driven and not all people active here live in the same timezone as you.

            From the thread I linked, you have the base to do the flip itself. From there you can create a new QGraphicsObject derived class and add a custom property that you will use with the animation framework to animate the flip.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Pippin
              wrote on last edited by
              #7

              @SGaist Thank you for your reply and sorry for the impatience.

              1. Would you mind dropping a very small code sample that would do the stuff you described? I'm not yet familiar with animations and properties, you'll be sparing me a lot - a lot - of time.

              2. About Qt itself. If I want to draw, say, 150 cards that each have a unique image while face-up, but all have the same image while face-down, and if all of them are face-down at a given time, Qt would be storing/drawing 150 identical QGraphicsPixmapItems whereas it would have been possible (with SFML for example) to store only 1 image and draw it 150 times. That looks very sub-optimal, but since Qt handles everything itself, I don't have much of a choice here, right?

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #8
                1. I wouldn't mind but I don't have it at hand, however the Animated Tile Example shows how to animate the position. You can adapt that for your needs.

                2. QPixmap is one of the implicitly shared classes of Qt so you would indeed get 150 items but they will use all the same pixmap. Not that you can create your own item that contains both pixmap and set the right one when you flip it.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Pippin
                  wrote on last edited by
                  #9

                  @SGaist Thanks for your reply.

                  1. I've already read that example, but it doesn't tackle my problem. I have no idea how to adapt it to flip tiles. I apologize if that's obvious :S
                  mrjjM 1 Reply Last reply
                  0
                  • P Pippin

                    @SGaist Thanks for your reply.

                    1. I've already read that example, but it doesn't tackle my problem. I have no idea how to adapt it to flip tiles. I apologize if that's obvious :S
                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Pippin
                    Hi this one is having flip code
                    https://blog.qt.io/blog/2009/06/09/flippin-widgets-medium-rare-please/
                    with animation. maybe you can reuse some of it.

                    P 1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @mrjj good one ! Indeed, the code easily be re-used since it's already using the graphics view framework.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Pippin
                        Hi this one is having flip code
                        https://blog.qt.io/blog/2009/06/09/flippin-widgets-medium-rare-please/
                        with animation. maybe you can reuse some of it.

                        P Offline
                        P Offline
                        Pippin
                        wrote on last edited by
                        #12

                        @mrjj Thanks a lot, that is very helpful. A bit old though (2009), I see a method rootState() that doesn't exist anymore.

                        mrjjM 1 Reply Last reply
                        0
                        • P Pippin

                          @mrjj Thanks a lot, that is very helpful. A bit old though (2009), I see a method rootState() that doesn't exist anymore.

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

                          @Pippin
                          indeed at bit old.
                          They talk about it here. (rootState())
                          http://stackoverflow.com/questions/7051146/qt-animation-member-doesnt-exist

                          QState *state1 = new QState(machine);
                          seems to be same as rootState

                          P 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @Pippin
                            indeed at bit old.
                            They talk about it here. (rootState())
                            http://stackoverflow.com/questions/7051146/qt-animation-member-doesnt-exist

                            QState *state1 = new QState(machine);
                            seems to be same as rootState

                            P Offline
                            P Offline
                            Pippin
                            wrote on last edited by
                            #14

                            @mrjj Thank you again. I've been willing to use your link but I would have questions.

                            How can I link a QState to a QGraphics(Pixmap)Item ? QState::assignProperty takes QObjects as first argument, but QGraphics(Pixmap)Item are not QObjects.

                            mrjjM 1 Reply Last reply
                            0
                            • P Pippin

                              @mrjj Thank you again. I've been willing to use your link but I would have questions.

                              How can I link a QState to a QGraphics(Pixmap)Item ? QState::assignProperty takes QObjects as first argument, but QGraphics(Pixmap)Item are not QObjects.

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

                              hi
                              i think you need to make you own QGraphicsObject
                              that controls the image drawing.
                              Then add a new property for switching the image to next one and
                              use that for QState::assignProperty

                              P 1 Reply Last reply
                              0
                              • mrjjM mrjj

                                hi
                                i think you need to make you own QGraphicsObject
                                that controls the image drawing.
                                Then add a new property for switching the image to next one and
                                use that for QState::assignProperty

                                P Offline
                                P Offline
                                Pippin
                                wrote on last edited by
                                #16

                                @mrjj said:

                                hi
                                i think you need to make you own QGraphicsObject
                                that controls the image drawing.
                                Then add a new property for switching the image to next one and
                                use that for QState::assignProperty

                                I'm really not familiar enough with Qt for that sadly... It's a real shame there is no simple way to do that. I'm a bit surprised that the beginner that I am finds right away something easy that is not easily done on Qt.

                                mrjjM 1 Reply Last reply
                                0
                                • P Pippin

                                  @mrjj said:

                                  hi
                                  i think you need to make you own QGraphicsObject
                                  that controls the image drawing.
                                  Then add a new property for switching the image to next one and
                                  use that for QState::assignProperty

                                  I'm really not familiar enough with Qt for that sadly... It's a real shame there is no simple way to do that. I'm a bit surprised that the beginner that I am finds right away something easy that is not easily done on Qt.

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

                                  @Pippin
                                  well the c++ of Qt does take some practice and knowledge of Class and subclasses and other
                                  c++ related topic. Once mastering common c++ methods, its not that hard as it else would seem.

                                  Did you have a look at QML ? its another qt way that is more easy in regards to more dynamic
                                  user interfaces.
                                  For example it can just flip
                                  http://doc.qt.io/qt-4.8/qml-flipable.html#details
                                  and tons of other easy to use features.

                                  P 1 Reply Last reply
                                  0
                                  • mrjjM mrjj

                                    @Pippin
                                    well the c++ of Qt does take some practice and knowledge of Class and subclasses and other
                                    c++ related topic. Once mastering common c++ methods, its not that hard as it else would seem.

                                    Did you have a look at QML ? its another qt way that is more easy in regards to more dynamic
                                    user interfaces.
                                    For example it can just flip
                                    http://doc.qt.io/qt-4.8/qml-flipable.html#details
                                    and tons of other easy to use features.

                                    P Offline
                                    P Offline
                                    Pippin
                                    wrote on last edited by
                                    #18

                                    @mrjj I don't know how to use QML, the tutorial shows code but I failed to understand where to put it / how to link it with the rest of the project. I'm doing everything through qmake, make and ./run in the terminal. I'm also not sure if QML can do anything I could do with C++ methods :S

                                    mrjjM 1 Reply Last reply
                                    0
                                    • P Pippin

                                      @mrjj I don't know how to use QML, the tutorial shows code but I failed to understand where to put it / how to link it with the rest of the project. I'm doing everything through qmake, make and ./run in the terminal. I'm also not sure if QML can do anything I could do with C++ methods :S

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

                                      @Pippin
                                      its not like c++
                                      there is a viewer program and you can also embed in c++
                                      http://www.ics.com/blog/whole-shebang-running-qml-files-directly
                                      Google is your friend
                                      You can mix with c++ so you can do most.
                                      But depends on what you really need for project.

                                      P 1 Reply Last reply
                                      0
                                      • mrjjM mrjj

                                        @Pippin
                                        its not like c++
                                        there is a viewer program and you can also embed in c++
                                        http://www.ics.com/blog/whole-shebang-running-qml-files-directly
                                        Google is your friend
                                        You can mix with c++ so you can do most.
                                        But depends on what you really need for project.

                                        P Offline
                                        P Offline
                                        Pippin
                                        wrote on last edited by
                                        #20

                                        @mrjj said:

                                        @Pippin
                                        its not like c++
                                        there is a viewer program and you can also embed in c++
                                        http://www.ics.com/blog/whole-shebang-running-qml-files-directly
                                        Google is your friend
                                        You can mix with c++ so you can do most.
                                        But depends on what you really need for project.

                                        The thing is, the QGraphicsView/Scene is only part of a window, which is part of my global project. How exactly do I insert QML inside a Qt project?

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

                                          hi
                                          you can use createWindowContainer
                                          http://www.ics.com/blog/combining-qt-widgets-and-qml-qwidgetcreatewindowcontainer
                                          or like this
                                          http://doc.qt.io/qt-4.8/qml-integration.html
                                          (check if works for 5.5)

                                          But if most of is c++ , it might be overkill to use QML just to draw some cards.
                                          Even if easy animation wise. You can try it out and see how much a hassle it is.

                                          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
                                          • Unsolved