yrandom
27th April 2017, 21:35
Hi
I make a Programm using C++ and Netbeans with a lot of pushbutton
I would like to do something like this
When i click the button, it should change to the Position i want and Change the border style or maybe Background to red or whatever and after maybe 300ms it should Change back to normal
The part with changing Position worked for me.
I used to Google but I didn found any solution. I try something like this but itsnot work
void VerschiebeSpiel::buttonClicked(QWidget* _button){
// Clicked button identifire with QSignalMapper
QPushButton* b = dynamic_cast<QPushButton*>(_button); //cast widget to pushbutton
int index = layout->indexOf(_button); // find out the index of button in gridlayout
int row, col,ax,bx;
if(index != -1){
layout->getItemPosition(index,&row,&col,&ax,&bx); // get the koordinate of this item
}
// Set border color
//b->setStyleSheet("border:2px solid #ff0000"); or set Background color
b->setStyleSheet("background-color:green");
//make delay time here to Show this Color for only a specific amoun of time like Sleep(MS) in Windows.h
// TODO
//QThread:usleep() seem not work, QTimer i think also dont work
b->setStyleSheet(""); // set stylesheet back
}
}
Any Solution for this?
Thanks
I make a Programm using C++ and Netbeans with a lot of pushbutton
I would like to do something like this
When i click the button, it should change to the Position i want and Change the border style or maybe Background to red or whatever and after maybe 300ms it should Change back to normal
The part with changing Position worked for me.
I used to Google but I didn found any solution. I try something like this but itsnot work
void VerschiebeSpiel::buttonClicked(QWidget* _button){
// Clicked button identifire with QSignalMapper
QPushButton* b = dynamic_cast<QPushButton*>(_button); //cast widget to pushbutton
int index = layout->indexOf(_button); // find out the index of button in gridlayout
int row, col,ax,bx;
if(index != -1){
layout->getItemPosition(index,&row,&col,&ax,&bx); // get the koordinate of this item
}
// Set border color
//b->setStyleSheet("border:2px solid #ff0000"); or set Background color
b->setStyleSheet("background-color:green");
//make delay time here to Show this Color for only a specific amoun of time like Sleep(MS) in Windows.h
// TODO
//QThread:usleep() seem not work, QTimer i think also dont work
b->setStyleSheet(""); // set stylesheet back
}
}
Any Solution for this?
Thanks