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. [SOLVED] How can i know what animations QPropertyAnimation can do?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How can i know what animations QPropertyAnimation can do?

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 14.6k 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.
  • L Offline
    L Offline
    Leon
    wrote on last edited by
    #1

    For example i know how to fade in/fade out a widget
    @ QGraphicsOpacityEffect* opacityEffect = new QGraphicsOpacityEffect(this);
    opacityEffect->setOpacity(1.0);
    time_for_next->setGraphicsEffect(opacityEffect);
    QPropertyAnimation* anim = new QPropertyAnimation(this);
    anim->setTargetObject(opacityEffect);
    anim->setPropertyName("opacity");
    anim->setDuration(500);
    anim->setStartValue(opacityEffect->opacity());
    anim->setEndValue(end_value);
    anim->setEasingCurve(QEasingCurve::OutQuad);
    anim->start(QAbstractAnimation::DeleteWhenStopped); @

    Or how to move/resize a widget with animation:

    @QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry");
    animation->setDuration(10000);
    animation->setStartValue(QRect(0, 0, 100, 30));
    animation->setEndValue(QRect(250, 250, 100, 30));
    animation->start();
    @

    But my question is were can i find a list with all the animations i can do?
    For example i want to animate the increasing of a label's text's font point size. Can i do it?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Well, you can animate basically everything that is exposed as a property. So, just look at the the available properties for your widget, and you know what you need.

      If you need to animate something that is not exposed as a property (like the font size), you can create a subclass that does expose the needed property.

      @
      class Label: public QLabel {
      Q_OBJECT
      Q_PROPERTY double fontPointSize READ fontPointSize WRITE setFontPointSize
      public:
      Label(QWidget* parent = 0): QLabel(parent) {}
      double fontPointSize() const {return font().pointSizeF();}
      Q_SLOT setFontPointSize(double size) {QFont f = font(); f.setPointSizeF(size); setFont(f);}
      }
      @

      Then, you can animate the shiney new fontPointSize property like any other property.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Leon
        wrote on last edited by
        #3

        you probably mean
        @Q_PROPERTY ( double fontPointSize READ fontPointSize WRITE setFontPointSize)
        @

        and

        @Q_SLOT void setFontPointSize(double size) {QFont f = font(); f.setPointSizeF(size); setFont(f);}
        @

        Anyhow what after creating the subclass what am i doing wrong?

        @QPropertyAnimation *animation = new QPropertyAnimation(ui->clock_label, "fontPointSize");
        animation->setDuration(5000);
        animation->setStartValue(10);
        animation->setEndValue(60);

        animation->start();@
        

        QPropertyAnimation: you're trying to animate a non-existing property fontPointSize of your QObject

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Yes, those corrections are correct. I just quickly typed into the forum editor.

          Silly question, but is ui->clock_label actually of the new class you created?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Leon
            wrote on last edited by
            #5

            I am kinda rookie on adding a class beside the MainWindow's one so its a bit confusing for me..

            This is my .h file
            @#ifndef MAINWINDOW_H
            #define MAINWINDOW_H

            #include <QMainWindow>
            #include "QPropertyAnimation"
            #include "QLabel"

            namespace Ui {
            class MainWindow;
            class Label;
            }

            class MainWindow : public QMainWindow
            {
            Q_OBJECT

            public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();

            private:
            Ui::MainWindow *ui;
            QPropertyAnimation *animation;
            };

            class Label: public QLabel {
            Q_OBJECT
            Q_PROPERTY (double fontPointSize READ fontPointSize WRITE setFontPointSize)

            public:
            Label(QWidget* parent = 0): QLabel(parent) {}
            double fontPointSize() const {return font().pointSizeF();}
            Q_SLOT void setFontPointSize(double size) {QFont f = font(); f.setPointSizeF(size); setFont(f);}

            private slots:
            void on_clock_label_linkActivated();
            };

            #endif // MAINWINDOW_H@

            And at my mainwindow.cpp i have this function:
            @void Label::on_clock_label_linkActivated()
            {

            QPropertyAnimation *animation = new QPropertyAnimation(ui->clock_label, "setFontPointSize");
            animation->setDuration(5000);
            animation->setStartValue(10);
            animation->setEndValue(60);
            
            animation->start();
            

            }@

            The text of the label (label added by qt designer):
            @<html><head/><body><p><a href="“textPassedToLinkActivatedSignal”"><span >text</span></a></p></body></html>@

            How can i when the user clicks the label run the void on_clock_label_linkActivated(); ?
            I mean it gives the error of ui not being declared..

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              I think that in your .ui file, you are still using a standard label.

              Split off your Label code into a set of files of its own: label.h and label.cpp. Then in your .ui file, right click on the label, and use the promote to... option so you can use your own Label instead of QLabel.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Leon
                wrote on last edited by
                #7

                Have never used promote either.. Xmm so what i did?
                Step 1: Created a clock_label.h and clock_label.cpp file (Via right clicking project->add new->C++ class)
                Step 2: Edited .h file code to:
                @#ifndef CLOCK_LABEL_H
                #define CLOCK_LABEL_H

                #include "QLabel"

                class clock_label
                {
                Q_OBJECT
                Q_PROPERTY (double fontPointSize READ fontPointSize WRITE setFontPointSize)

                public:
                clock_label();
                Label(QWidget* parent = 0): QLabel(parent) {}
                double fontPointSize() const {return font().pointSizeF();}
                Q_SLOT void setFontPointSize(double size) {QFont f = font(); f.setPointSizeF(size); setFont(f);}
                };

                #endif // CLOCK_LABEL_H@
                Step 3:Went at the designer right clicked the label->promote to
                In promoted class name i putted clock_label, then i clicked add and then promote
                And i can see in the designer it now shows clock_label instead of QLabel.

                But now i have errors like
                error: ISO C++ forbids declaration of 'Label' with no type [-fpermissive]
                error: type 'QLabel' is not a direct base of 'clock_label'

                what i did wrong at the .h file?

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  Your clock_label doesn't derive from QLabel...

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    Leon
                    wrote on last edited by
                    #9

                    That being said, can u point me out in what step have i done something wrong?

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #10

                      Compare line 6 of the code that you just posted with line 1 of the sample I posted earlier...

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        Leon
                        wrote on last edited by
                        #11

                        You are right,
                        thank you and i appreciate your time ;)

                        1 Reply Last reply
                        0
                        • L Offline
                          L Offline
                          Leon
                          wrote on last edited by
                          #12

                          I really don't get how i should subclass the property..

                          for example Andre's code
                          @ Q_PROPERTY (double fontPointSize READ fontPointSize WRITE setFontPointSize)
                          double fontPointSize() const {return font().pointSizeF();}
                          Q_SLOT void setFontPointSize(double size) {QFont f = font();@

                          how to change this code to work for the minimumwidth?

                          @ Q_PROPERTY (double minimumWidth READ minimumWidth WRITE setMinimumWidth)
                          double minimumWidth() const {return minimumWidth();}
                          Q_SLOT void setMinimumWidth(double size) {setMinimumWidth(size);}@

                          Why isn't the above code working but instead it freezes the application...

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            Why would you want this, since minimumWidth is already a property?

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              Leon
                              wrote on last edited by
                              #14

                              You are right it works if i dont subclass it..
                              Ok now i understand.. i should have gone here "QWidget Class Reference":http://doc.qt.digia.com/qt/qwidget.html and check if minimumwidth is a property..

                              Well i was looking at QLabel's class reference and that's why i got confused...
                              thanks again ;)

                              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