×

Discussion Board

Results 1 to 14 of 14
  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Animation Problem

    Hi,
    I have attached a small piece of code which shows animation of button on HOME SCREEN.This is done only when we have this code in main function.
    I want it to animate in CLIENT AREA.
    I tried to use the same code in a constructor of other class defined in main.
    But it did not work out.

    Code:
    QPushButton button("Animated Button");
    
    	button.show();
    
    	QPropertyAnimation animation(&button, "geometry");
    	animation.setDuration(10000);
    	animation.setStartValue(QRect(0, 0, 100, 30));
    	animation.setEndValue(QRect(250, 250, 100, 30));
    	animation.start();

    Can anyone please help me for this problem

    Chirpylife

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Animation Problem

    What is client area?

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    Client Area, I mean is the area where your application is displayed

    Chirpylife

  4. #4
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,777

    Re: Animation Problem

    Quote Originally Posted by chirpylife View Post
    Client Area, I mean is the area where your application is displayed

    Chirpylife
    Is this what you mean?
    Code:
    #include <QtGui/QApplication>
    #include "mainwindow.h"
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        QPushButton button("Animated Button", &w);
    
        button.show();
    
        QPropertyAnimation animation(&button, "geometry");
        animation.setDuration(10000);
        animation.setStartValue(QRect(0, 0, 100, 30));
        animation.setEndValue(QRect(250, 250, 100, 30));
        animation.start();
    
        return a.exec();
    }
    Pankaj Nathani
    www.croozeus.com

  5. #5
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Animation Problem

    Quote Originally Posted by croozeus View Post
    Is this what you mean?
    I think it's much better this way. But I still don't get what the original problem is.
    What is a home screen then?

    Code:
    #include <QApplication>
    #include <QMainWindow>
    #include <QPushButton>
    #include <QPropertyAnimation>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QMainWindow w;
        QPushButton button("Animated Button", &w);
    
        w.show();
    
        QPropertyAnimation animation(&button, "geometry");
        animation.setDuration(10000);
        animation.setStartValue(QRect(0, 0, 100, 30));
        animation.setEndValue(QRect(250, 250, 100, 30));
        animation.start();
    
        return a.exec();
    }
    Last edited by divanov; 2010-03-04 at 09:32.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    hi,
    If you run the following code which i attached it displays a button being animated .
    The place where its shown is called as Home Screen.
    Now run it with comments removed from the code.
    the button does not animate completely.I said this area to be Client Area.
    Can you help me in making the button display complete animation when the comments in the code are removed.

    Am sorry if i was wrong in defining home screen and client area.
    Hope you got my problem now.

    Code:
    #include "example.h"
    #include <QtGui>
    #include <QApplication>
    #include <QMainWindow>
    #include <QPushButton>
    #include <QPropertyAnimation>
    
    
    int main(int argc, char *argv[])
    {
    
      QApplication a(argc, argv);
       //example w;
        QPushButton button("Animated Button");
          	button.show();
        	QPropertyAnimation animation(&button, "geometry");
        	animation.setDuration(10000);
        	animation.setStartValue(QRect(0, 0, 100, 30));
        	animation.setEndValue(QRect(250, 250, 100, 30));
        	animation.start();
        //w.showMaximized();
        return a.exec();
    }

    Chirpylife

  7. #7
    Nokia Developer Moderator
    Join Date
    May 2007
    Location
    21.46 N 72.11 E
    Posts
    3,777

    Re: Animation Problem

    Doesn't this do what you want? Did you try it?

    I am still unclear about what you mean, but as far as I can understand, you want the button to be inside the widget (or the mainwindow) and animate.

    Quote Originally Posted by croozeus View Post
    Code:
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
    
        QPushButton button("Animated Button", &w);
    
        w.show();
    
        QPropertyAnimation animation(&button, "geometry");
        animation.setDuration(10000);
        animation.setStartValue(QRect(0, 0, 100, 30));
        animation.setEndValue(QRect(250, 250, 100, 30));
        animation.start();
    
        return a.exec();
    }
    Pankaj Nathani
    www.croozeus.com

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    Am sorry Pankaj.Yes It worked now...
    Now my problem was to use the same code in constructor of example w am not able to get animation.
    if i use any of these lines in example.cpp it says

    QPushButton button("Animated Button",&w); //error because of w

    QPushButton button("Animated Button");//No error but button does not get displayed

    QPushButton button("Animated Button",this);//No error but button does not get displayed

    Code:
    //MAIN
    
    #include "example.h"
    #include <QMainWindow>
    #include <QPushButton>
    #include <QPropertyAnimation>
    #include <QtGui/QApplication>
    
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        example w;
        w.show();
        return a.exec();
    }
    Code:
    //example.cpp
    #include "example.h"
    #include <qpushbutton.h> 
    
    #include <QtGui>
    #include <QFrame>
    #include <QWidget>
    #include <QLabel>
    #include <QDockWidget>
    #include <QStatusbar>
    #include <QToolButton>
    #include <QPalette>
    #include <QDesktopWidget>
    #include <QtGui>
    #include <QApplication>
    
    example::example(QWidget *parent) :
    	QMainWindow(parent)
    	{
    	ui.setupUi(this);
               QPushButton button("Animated Button", &w);
    	    QPropertyAnimation animation(button, "geometry");
    	    animation.setDuration(10000);
    	    animation.setStartValue(QRect(0, 0, 100, 30));
    	    animation.setEndValue(QRect(250, 250, 100, 30));
    	    animation.start();
    	
    	
    	}
    k::~k()
    	{
    
    	}
    Can you help me here...

    Chirpylife

  9. #9
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Animation Problem

    You have to create button and property animation dynamically using operator new.
    Code:
    button = new QPushButton("Animated Button", this);
    QPropertyAnimation *animation = new QPropertyAnimation(button, "geometry", button);
    animation->setDuration(10000);
    animation->setStartValue(QRect(0, 0, 100, 30));
    animation->setEndValue(QRect(250, 250, 100, 30));
    animation->start();

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    Thanks a lot Daniil
    My problem is solved..

    Chirpylife

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    Hi guys
    I ended up with new problem now...
    I want to use image instead of button here..

    QPropertyAnimation *animation = new QPropertyAnimation(button, "geometry", button);

    But QPropertyAnimation accepts QOjects as parameter..and QPixmap doesnt support it...
    Is there any other possible way to animate image???
    Help me

    Chirpylife

  12. #12
    Nokia Developer Moderator
    Join Date
    Oct 2009
    Posts
    4,326

    Re: Animation Problem


  13. #13
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    Hi,
    Am unable to find y this code doesnt show any image...
    Code:
    Anim::Anim(QWidget *parent) :
    	QMainWindow(parent)
    	{
    	ui.setupUi(this);
    
    	//	ani();
    
    	}
    Anim::~Anim()
    	{
    
    	}
    void Anim::mousePressEvent(QMouseEvent *event)
    	{
    	QPoint point1 = event->pos();
    	ani();
    	}
    void Anim::ani()
    	{
    
    	p1.load(":/new/prefix1/cards/card2.png");
    	QLabel *label = new QLabel(this);
    	label->setPixmap(p1);
    	label->setMaximumSize(40, 40);
    
    	QPropertyAnimation *animation = new QPropertyAnimation(label, "geometry",
    			label);
    	animation->setDuration(10000);
    	animation->setStartValue(QRect(0, 0, 100, 30));
    	animation->setEndValue(QRect(150, 150, 100, 30));
    	animation->setEasingCurve(QEasingCurve::InOutQuad);
    	animation->start();
    
    	}
    when we call the function ani() from constructor it works properly.
    If we want to call the function on mouse press event it doesnt display image.
    Can you guide me whats happening here...
    when we debug it shows that it is reaching ani() function on mouse click,but it doesnt display...Any idea???

    Chirpylife
    Last edited by chirpylife; 2010-03-05 at 10:58.

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    37

    Re: Animation Problem

    got solution...
    load image in constructor...it works

Similar Threads

  1. 编译Qt样例出错,请看如下
    By TD3 in forum [Archived] Qt General ( Qt技术)
    Replies: 14
    Last Post: 2009-12-24, 03:23
  2. Problem with CAknDoubleStyleListBox with a CAknSearchField
    By jjig in forum Symbian User Interface
    Replies: 2
    Last Post: 2009-09-17, 00:58
  3. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36
  4. Http client api, animation delay
    By 1xuname1x in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2004-10-11, 07:40
  5. Problem with Sprite Animation
    By ramka001 in forum Mobile Java General
    Replies: 1
    Last Post: 2003-05-08, 10:11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •