I've written a program with different functions in Qt. Now I want to make a Gui. For example I have two buttons, button1 and button2. I open the application, i see button1 first. Then I click button1, it executes its function (like "start") and disappears. Then button2 should appear and when I click button2 it executes its function (like "stop") and disappears and button1 shows up again to be clicked to execute start. My question now is, how to solve this in an easy way?
void gui::on_pushButton_clicked()
{
//execute start, switch to be button2
}
void gui::on_pushButton_2_clicked()
{
//execute stop, switch to be button 1
}
The following seems to be the easiest solution, but a bit cumbersome in case you want to add more buttons. In that case you might want to consider storing them in a list and iterating the list.
void gui::on_pushButton_clicked()
{
//execute start, switch to be button2
ui->pushButton->hide();
ui->pushButton_2->show();
}
void gui::on_pushButton_2_clicked()
{
//execute stop, switch to be button 1
ui->pushButton->show();
ui->pushButton_2->hide();
}
If you further on decide to implement even more logic, you should consider using QStateMachine and setting certain buttons to visible or hidden when entering or exiting certain states.