You do not create the currentIndexChanged() signal - the combo box emits that. You need to connect your own slot to it, and in the slot you need to do something like this:
// constructor
MyTabWidget
::MyTabWidget( QWidget * parent
){
// setupUi, etc...
connect( myComboBox, &QComboBox::currentIndexChanged, this, &MyTabWidget::updateCheckboxes );
}
// slot
void MyTabWidget::updateCheckboxes(int comboBoxIndex)
{
switch( comboBoxIndex )
{
case 0:
// enable checkboxes base on selection of first item in combobox
break;
case 1:
// enable checkboxes base on selection of second item in combobox
break;
// etc.
default:
break;
}
}
// constructor
MyTabWidget::MyTabWidget( QWidget * parent )
: QTabWidget( parent )
{
// setupUi, etc...
connect( myComboBox, &QComboBox::currentIndexChanged, this, &MyTabWidget::updateCheckboxes );
}
// slot
void MyTabWidget::updateCheckboxes(int comboBoxIndex)
{
switch( comboBoxIndex )
{
case 0:
// enable checkboxes base on selection of first item in combobox
break;
case 1:
// enable checkboxes base on selection of second item in combobox
break;
// etc.
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
You might have to initialize things by calling updateCheckboxes( 0 ) in the constructor (using whatever the default startup index should be from the combobox). This makes sure that when the app first comes up, the checkboxes are in the correct states for whatever item appears by default in the combobox. If you set the initial index to -1 (no selection), then you will probably want to disable all of the checkboxes.
If your combobox does not have a fixed number of items in it (for example, the choices are loaded from a file, database, or are determined in some other way), then obviously a switch statement won't work unless the "default:" clause is very smart. It does not sound like this is your problem though.
Bookmarks