[SOLVED] How can i know what animations QPropertyAnimation can do?
-
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? -
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.
-
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
-
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_OBJECTpublic:
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.. -
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.
-
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?
-
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...
-
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 ;)