Results 1 to 9 of 9

Thread: Moving of Button

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving of Button

    That's bad... If you wanted to just animate a button, that would be very easy. But if you have to do it "by timer" then I'm afraid you have some weird problem in your code you will have to fix. That might have to do something with the fact you are creating a new button each time the slot is called.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    8Observer8 (10th November 2014)

  3. #2
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: Moving of Button

    Thank you very much! It works normally now:

    Qt Code:
    1. #include "Dialog.h"
    2. #include "ui_Dialog.h"
    3.  
    4. Dialog::Dialog(QWidget *parent) :
    5. QDialog(parent),
    6. ui(new Ui::Dialog),
    7. x( 20 ),
    8. y( 20 )
    9. {
    10. ui->setupUi(this);
    11.  
    12. horse1 = new QPushButton( this );
    13.  
    14. connect( &m_timer, SIGNAL( timeout() ),
    15. this, SLOT( slotUpdate() ) );
    16. m_timer.start( 50 );
    17. //this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
    18. }
    19.  
    20. Dialog::~Dialog()
    21. {
    22. delete ui;
    23. }
    24.  
    25. void Dialog::slotUpdate()
    26. {
    27.  
    28. horse1->setGeometry( 20+x, 20+y, 50, 50 );
    29. //horse1->setStyleSheet("background-color: rgb(177, 177, 177);" "color: black;");
    30.  
    31. //m_horses.push_back( horse1 );
    32.  
    33. horse1->show();
    34. ++x;
    35. ++y;
    36. //this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
    37. update();
    38. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Moving of Button

    Still, if you decide that maybe you don't have to do it by using a timer, you might have a look at QPropertyAnimation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    8Observer8 (10th November 2014)

  6. #4
    Join Date
    Nov 2012
    Posts
    232
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Platforms
    Windows Android

    Default Re: Moving of Button

    Ok! Thank you!

Similar Threads

  1. Replies: 2
    Last Post: 26th April 2011, 11:44
  2. Replies: 6
    Last Post: 21st August 2010, 21:09
  3. Replies: 1
    Last Post: 2nd August 2010, 05:40
  4. Replies: 0
    Last Post: 24th May 2010, 12:19
  5. Moving QToolBar Button
    By mbrusati in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 13:29

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
  •  
Qt is a trademark of The Qt Company.