3

Is it possible to deactivate a QSpinBox if a certain value is chosen in a QComboBox. I've tried several things, but either the QSpinbox is deactived all the time or it wont deactivate at all.

buddy
  • 821
  • 2
  • 12
  • 30

1 Answers1

8

If I understand the question correctly, something along these lines should work:

connect( myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(comboBoxIndexChanged()) );

...

void comboBoxIndexChanged() {
    if( comboBox->currentText() == MagicalValue )
        mySpinBox->setEnabled( false );
    else
        mySpinbox->setEnabled( true );
}
Chris
  • 17,119
  • 5
  • 57
  • 60
  • 1
    A more compact version of the slot function would be `void comboBoxIndexChanged() { mySpinBox->setEnabled( comboBox->currentText() != MagicalValue ); }` – Hossein Mar 24 '12 at 10:49