[Qt-interest] Sleep

Tim W timpie.w at gmail.com
Tue Apr 7 16:29:05 CEST 2009


On Tue, Apr 7, 2009 at 8:46 AM, Parameshwari <paramr at tataelxsi.co.in> wrote:

>
>
> but i wanted to add a sleep before resize option, So that i will get the
> slider effect.some one could help in this.
>
>
>

Try not to suspend the gui thread.
I think you need something like this ...

//header
#include <QObject>
#include <QSize>
#include <boost/function.hpp>

class QTimeLine;

class ResizeAnimation : public QObject
{
    Q_OBJECT
public:
    typedef boost::function< void (int, int) > Resize;

    explicit ResizeAnimation( QObject* const aParent );
    void setResizeObject( const Resize& aResizableObject, const QSize&
aEndSize );

    public slots:
        void start();

        private slots:
            void nextFrame(int aFrame );

private:
    QTimeLine *const m_timeLine;
    QSize m_size;
    Resize m_resizable;
};

//cpp
#include "resizeanimation.h"
#include <QTimeLine>

ResizeAnimation::ResizeAnimation( QObject* const aParent )
: QObject(aParent),
  m_timeLine( new QTimeLine( 2000, this ) ),
  m_size(),
  m_resizable()
{
    connect( m_timeLine, SIGNAL( frameChanged( int ) ), SLOT(nextFrame(int))
);
    m_timeLine->setLoopCount( 5 );
}


void ResizeAnimation::setResizeObject( const Resize& aResizableObject, const
QSize& aEndSize )
{
    m_resizable =aResizableObject;
    m_size = aEndSize;
    m_timeLine->setFrameRange(0, qMax( aEndSize.width(), aEndSize.height() )
);
}

void ResizeAnimation::start()
{
    m_timeLine->start();
}

void ResizeAnimation::nextFrame(int aFrame )
{
    if(!m_resizable)
    {
        m_resizable(qMin( aFrame, m_size.width() ), qMin( aFrame,
m_size.height() ));
    }
}

//user code


#include <QtGui/QApplication>
#include <QtGui/QWidget>
#include <boost/lambda/bind.hpp>
#include <boost/ref.hpp>

using namespace boost::lambda;
using namespace boost;


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget widgetToResize;
    widgetToResize.resize( 0, 0 );
    widgetToResize.show();

    ResizeAnimation animation(0);
    void (QWidget::*resize)( int, int ) = &QWidget::resize;
    animation.setResizeObject( bind(resize, &widgetToResize, _1, _2), QSize(
500,500 ));
    animation.start();
    return a.exec();
}



Cheers,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090407/f13dab0f/attachment.html 


More information about the Qt-interest-old mailing list