PDA

View Full Version : Moving of Button



8Observer8
10th November 2014, 14:38
Hello!

Help me to delete this:

10741



#include "Dialog.h"
#include "ui_Dialog.h"

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog),
x( 20 ),
y( 20 )
{
ui->setupUi(this);

connect( &m_timer, SIGNAL( timeout() ),
this, SLOT( slotUpdate() ) );
m_timer.start( 50 );
//this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
}

Dialog::~Dialog()
{
delete ui;
}

void Dialog::slotUpdate()
{
QPushButton *horse1 = new QPushButton( this );
horse1->setGeometry( 20+x, 20+y, 50, 50 );
//horse1->setStyleSheet("background-color: rgb(177, 177, 177);" "color: black;");

//m_horses.push_back( horse1 );

horse1->show();
++x;
++y;
//this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
update();
}

anda_skoa
10th November 2014, 16:03
Is there a question in there somewhere?

Cheers,
_

8Observer8
10th November 2014, 16:07
I want to move a button by timer. But I see this trace how in the picture. How to delete this trace?

wysota
10th November 2014, 16:52
I want to move a button by timer.

Do you want to "move a button" or "move a button by timer"?

8Observer8
10th November 2014, 16:53
Yes, yes! Sorry for my English: move a button by timer Please, help me!

wysota
10th November 2014, 16:59
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.

8Observer8
10th November 2014, 17:07
Thank you very much! It works normally now:



#include "Dialog.h"
#include "ui_Dialog.h"

Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog),
x( 20 ),
y( 20 )
{
ui->setupUi(this);

horse1 = new QPushButton( this );

connect( &m_timer, SIGNAL( timeout() ),
this, SLOT( slotUpdate() ) );
m_timer.start( 50 );
//this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
}

Dialog::~Dialog()
{
delete ui;
}

void Dialog::slotUpdate()
{

horse1->setGeometry( 20+x, 20+y, 50, 50 );
//horse1->setStyleSheet("background-color: rgb(177, 177, 177);" "color: black;");

//m_horses.push_back( horse1 );

horse1->show();
++x;
++y;
//this->setStyleSheet( "background-color: rgb(177, 177, 177);" "color: black;" );
update();
}

wysota
10th November 2014, 17:11
Still, if you decide that maybe you don't have to do it by using a timer, you might have a look at QPropertyAnimation.

8Observer8
10th November 2014, 17:21
Ok! Thank you!