QPushButton *myButton = new QPushButton("Click me"); myButton->setEnabled(false);
QLineEdit *myTextBox = new QLineEdit(); bool isEnabled = true; myTextBox->setEnabled(isEnabled); // Later in code, toggle the enabled state isEnabled = !isEnabled; myTextBox->setEnabled(isEnabled);In this example, a QLineEdit object is created and initially set to be enabled. Later in the code, the enabled state is toggled by setting the isEnabled variable to its opposite value and calling setEnabled with the new value. Package library: Qt.