I will start by describing my C++ GUI app.
I have a home screen (mainwindow) which has a number of labels(kpi's) that show various data. And there is a settings button in the home screen, pressing which a settings dialog (consettingsdialog) opens which has various parameter settings for the mainwindow labels and the application itself. The settings parameters are saved after pressing the save button in consettingsdialog.
My target is to make certain labels in the mainwindow visible / invisible if corresponding checkboxes are checked or unchecked in the consettingsdialog.
This is the details what I have done so far;
in my consettingsdialog.cpp
ConSettingsDialog::ConSettingsDialog(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
kpi1CheckBox->setChecked(true);
}
void ConSettingsDialog :: onSaveButton()
{
if(kpi1CheckBox->isChecked()==true)
{
kpi1CheckBox->setChecked(true);
emit setHomeScreenKpiVisibility();
}
else
{
kpi1CheckBox->setChecked(false);
emit setHomeScreenKpiInvisibility();
}
}
in my mainwindow.cpp
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_ConSettingsDialog =new ConSettingsDialog();
connect(m_ConSettingsDialog,SIGNAL(setHomeScreenKpiVisibility()),this,SLOT(setHomeScreenKpiVisibility()));
connect(m_ConSettingsDialog,SIGNAL(setHomeScreenKpiInvisibility()),this,SLOT(setHomeScreenKpiInvisibility()));
}
void MainWindow::setHomeScreenKpiVisibility()
{
ui->mylabel->setVisible(true);
}
void MainWindow::setHomeScreenKpiInvisibility()
{
ui->mylabel->setVisible(false);
}
The code builds up perfectly without any errors, but when I run it no matter how many times I uncheck the checkbox, the label stays visible. And when I open the consettings I see the checkbox is checked.
I tried by changing kpi1CheckBox->setChecked(true);
in the consettingsdialog.cpp to kpi1CheckBox->setChecked(false);
but then also the label in home screen stays visible (not invisible at all). Although in this case the checkbox in settings dialog is set permanently disabled.
Feeling completely stuck now, what am I doing wrong ?