I am using a StackedLayout and Buttons to switch between screens. I have a separate style for if a button is checked or not. I am also using keyPressEvent to switch between stacks instead of clicking on a button to switch.

When I use the keyPress event, I can switch between stacks, but the buttons don't change from unchecked to checked.

I have 4 buttons and for each I wrote methods to see if the button is checked or not, like so:

```
bool MainWindow::dashBoardButton_isChecked() {
    if(ui->dashBoardButton->isChecked()) {
        return true;
    } else {
        return false;
    };

    return false;
};

```

and when I switch between stacks, I use this method:

```
void MainWindow::on_dashBoardButton_clicked() {
    ui->mainStack->setCurrentIndex(0);

    if(!dashBoardButton_isChecked()) {
        ui->dashBoardButton->setChecked(true);
    };

};

```

I do this 4 times for each button/stack. This seems to me to be a little repetitive. Is there some way I could shorten the code, and maybe instead of having 4 very similar methods, have one method that instead?