Results 1 to 9 of 9

Thread: Moving of Button

  1. #1
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Moving of Button

    Hello!

    Help me to delete this:

    441.png

    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. connect( &m_timer, SIGNAL( timeout() ),
    13. this, SLOT( slotUpdate() ) );
    14. m_timer.start( 50 );
    15. //this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
    16. }
    17.  
    18. Dialog::~Dialog()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void Dialog::slotUpdate()
    24. {
    25. QPushButton *horse1 = new QPushButton( this );
    26. horse1->setGeometry( 20+x, 20+y, 50, 50 );
    27. //horse1->setStyleSheet("background-color: rgb(177, 177, 177);" "color: black;");
    28.  
    29. //m_horses.push_back( horse1 );
    30.  
    31. horse1->show();
    32. ++x;
    33. ++y;
    34. //this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
    35. update();
    36. }
    To copy to clipboard, switch view to plain text mode 

  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 of Button

    Is there a question in there somewhere?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    8Observer8 (10th November 2014)

  4. #3
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Moving of Button

    I want to move a button by timer. But I see this trace how in the picture. How to delete this trace?

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

    Default Re: Moving of Button

    Quote Originally Posted by 8Observer8 View Post
    I want to move a button by timer.
    Do you want to "move a button" or "move a button by timer"?
    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.


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

    8Observer8 (10th November 2014)

  7. #5
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Moving of Button

    Yes, yes! Sorry for my English: move a button by timer Please, help me!

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


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

    8Observer8 (10th November 2014)

  10. #7
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    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 

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 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.


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

    8Observer8 (10th November 2014)

  13. #9
    Join Date
    Nov 2012
    Location
    Russia
    Posts
    231
    Thanks
    118
    Thanked 18 Times in 10 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Moving of Button

    Ok! Thank you!

Similar Threads

  1. Replies: 2
    Last Post: 26th April 2011, 12:44
  2. Replies: 6
    Last Post: 21st August 2010, 22:09
  3. Replies: 1
    Last Post: 2nd August 2010, 06:40
  4. Replies: 0
    Last Post: 24th May 2010, 13:19
  5. Moving QToolBar Button
    By mbrusati in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 14: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.