[SOLVED] How can i know what animations QPropertyAnimation can do?
-
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?
-
Your clock_label doesn't derive from QLabel...
-
That being said, can u point me out in what step have i done something wrong?
-
Compare line 6 of the code that you just posted with line 1 of the sample I posted earlier...
-
You are right,
thank you and i appreciate your time ;) -
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...
-
Why would you want this, since minimumWidth is already a property?
-
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 ;)