[Qt-interest] Sleep

Parameshwari paramr at tataelxsi.co.in
Thu Apr 16 12:55:27 CEST 2009


Hi ,
                 Thanks for the Input.Now, the sleep is added. But the
problem is , i am getting one more cmd prompt when i am including QTEST
library in my ".pro" file.How to avoid that. Or is there any other way to
make delay or sleep ?

Thanks in advance.

-param

  -----Original Message-----
  From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com]On Behalf Of Parameshwari
  Sent: Wednesday, April 08, 2009 10:05 AM
  To: 'Tim W'
  Cc: qt-interest at trolltech.com
  Subject: Re: [Qt-interest] Sleep


  Use "QTest::qWait(1);" before entering to resize.. this will help for
sleep..
  you need to add "QT += testlib" in ".pro" file if you are using Qt 4.5.0 .


  Regards
  param

    [Parameshwari]  -----Original Message-----
    From: Tim W [mailto:timpie.w at gmail.com]
    Sent: Tuesday, April 07, 2009 7:59 PM
    To: paramr at tataelxsi.co.in
    Cc: qt-interest at trolltech.com
    Subject: Re: [Qt-interest] Sleep




    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/20090416/5a50dca0/attachment.html 


More information about the Qt-interest-old mailing list