Results 1 to 7 of 7

Thread: Moving MainWindow , Dialog Window \ Animated Move

  1. #1
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Question Moving MainWindow , Dialog Window \ Animated Move

    Hello first time poster here so i guese an intreduction is in order.
    Hello am Kjell 'WetCode' Bjarre (25) and am a complete Qt noob.

    So here is my question:.

    What i want to do is have a dialog slide out from the top right corner of the screen "hover" for x seconds and slide back in again and close.
    I set up my little main window and a button that`s suposed to trigger the "notification" in the top right corner.
    Well i don`t know how i would move that image i found some functions like ::setX(int ) and Y but that don`t work, can`t find anything on it in the help. (I know its there i just cant find it).

    So i tried setting up a timer that was connected the timer with the timeout() and set the slot to update() in this (beeing the dialog "pop up" window)
    in a for loop that would basically move the window from X, Y = 0 to 400. That dont work ether so am hoping someone here can point me in the direction of the correct classes and functions.

    Thanks for reading all this and BTW i have these express in with amazon on Thursday so i hope i wont be a bother to long.
    * Foundations of Qt Development (Expert's Voice in Open Source)
    * C++ GUI Programming with Qt 4 (2nd Edition) (Prentice Hall Open Source Software Development Series)
    * Advanced Qt Programming: Creating Great Software with C++ and Qt 4 (Prentice Hall Open Source Software Development)


    I realy want to learn and can`t wait for the books so any help while i wait i is much aprichiated.

    Cheers
    WetCode
    Last edited by WetCode; 8th January 2013 at 20:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Moving MainWindow , Dialog Window \ Animated Move

    There is no event processing as long as you are in a for loop. So when you iterate over the value range, only the final position will be drawn.

    Each invocation of the slot connected to the timer needs to increase the values a bit and then exit, letting the system handle the events that this partial move has caused.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Moving MainWindow , Dialog Window \ Animated Move

    Thank you so much for your reply.
    I am allready luanching Qt Creator to have a go at modifying my code.
    but where the functions correct for my intentions or do you think i should use some other methods?

    Cheers
    WetCode

  4. #4
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Moving MainWindow , Dialog Window \ Animated Move

    Forgor to put my sulution up here so bether late then never I hope...

    Qt Code:
    1. void MainWindow::moveWindow()
    2. {
    3. thread.start();
    4. for (int i = 0; i < 80 ; i++)
    5. {
    6. thread.wait( 1 );
    7. xPoint->setX( pos().x() + 3 );
    8. xPoint->setY( pos().y() + 3 );
    9. move(*xPoint);
    10. }
    11. thread.quit();
    12. }
    To copy to clipboard, switch view to plain text mode 

    Hope it helps someone and please correct me if i have done somthing "wrong" here.

    Cheers
    WetCode
    Last edited by WetCode; 14th January 2013 at 20:18.

  5. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Moving MainWindow , Dialog Window \ Animated Move

    Qt has mechanisms specifically for the purpose of "animating" widgets and the like: Animation Framework, specifically QPropertyAnimation. They work entirely within the normal Qt event processing, no threads or explicit looping required, and your program can be doing actual work at the same time.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class SelfAnimator: public QWidget
    4. {
    5. Q_OBJECT
    6. public:
    7. SelfAnimator(QWidget *p = 0): QWidget(p) {
    8. resize(200, 200);
    9.  
    10. // Start a slide on to the screen
    11. QPropertyAnimation *slideIn = new QPropertyAnimation(this, "pos");
    12. slideIn->setEasingCurve(QEasingCurve(QEasingCurve::OutQuad)); // optional, linear by default
    13. slideIn->setDuration(5000);
    14. slideIn->setStartValue(QPoint(-200, -200));
    15. slideIn->setEndValue(QPoint(0, 0));
    16. slideIn->start();
    17. connect(slideIn, SIGNAL(finished()), SLOT(slideInFinished()));
    18. connect(slideIn, SIGNAL(finished()), slideIn, SLOT(deleteLater()));
    19. }
    20.  
    21. private slots:
    22. void slideInFinished() {
    23. // Organise to wait a while
    24. QTimer::singleShot(3000, this, SLOT(pauseFinished()));
    25. }
    26.  
    27. void pauseFinished() {
    28. // Done waiting, let's leave
    29. QPropertyAnimation *slideOut = new QPropertyAnimation(this, "pos");
    30. slideOut->setEasingCurve(QEasingCurve(QEasingCurve::InQuad));
    31. slideOut->setDuration(5000);
    32. slideOut->setStartValue(QPoint(0, 0));
    33. slideOut->setEndValue(QPoint(-200, -200));
    34. slideOut->start();
    35. connect(slideOut, SIGNAL(finished()), SLOT(slideOutFinished()));
    36. connect(slideOut, SIGNAL(finished()), slideOut, SLOT(deleteLater()));
    37. }
    38.  
    39. void slideOutFinished() {
    40. qApp->quit();
    41. }
    42. };
    43.  
    44.  
    45. int main(int argc, char **argv)
    46. {
    47. QApplication app(argc, argv);
    48. SelfAnimator w;
    49. w.show();
    50. return app.exec();
    51. }
    52. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to ChrisW67 for this useful post:

    WetCode (14th January 2013)

  7. #6
    Join Date
    Jan 2013
    Posts
    23
    Thanks
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Moving MainWindow , Dialog Window \ Animated Move

    Hello and thanks for your great reply i was shure it was a bether \ correct way to do this.
    But am guesing am not that far in to the book`s and Qt yet. Thanks again you gave me a bit of a boost.
    Today I have been strugeling to understand chapter 3 in C++ GUI Programming with Qt 4 (2nd) "MainWindow" fully.

    So it was nice to see yet another Qt :O
    EDIT: Correct me if am wrong but the SelfAnimation class is your making right?

    Cheers
    WetCode
    Last edited by WetCode; 14th January 2013 at 22:32.

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Moving MainWindow , Dialog Window \ Animated Move

    Yes, SelfAnimator is mine. It just demonstrates one way you may use the Qt animation framework.

Similar Threads

  1. Right approach for moving animated objects
    By AndyQT in forum Newbie
    Replies: 5
    Last Post: 6th November 2012, 09:39
  2. Replies: 4
    Last Post: 17th August 2010, 19:38
  3. Replies: 1
    Last Post: 15th August 2010, 21:40
  4. Replies: 0
    Last Post: 9th May 2010, 20:49
  5. Replies: 3
    Last Post: 23rd July 2006, 18:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.