How to set a Background colour for Disabled Pushbuttons
-
Actually i have Accessing all buttons in the same slot ,by using list. here i am able to disable the clicked button. And i want to set color for disabled buttons ,
and this is my code ,
void MainWindow::ButtonClicked() { QPushButton *Button = qobject_cast<QPushButton *> ( sender()); if (Button) { QString Text = Button->text(); qDebug() << "check" << Text; FinalFile.append(Text); // keep for later till we save ok ? Button->setEnabled(false); // Button->setStyleSheet(":enabled { color: " + foreground + "; background-color: " + color + "}"); // i dont know this one is correct or not } }
Say me some suggestions to set a color for disable buttons
thanks in advance .. -
Actually i have Accessing all buttons in the same slot ,by using list. here i am able to disable the clicked button. And i want to set color for disabled buttons ,
and this is my code ,
void MainWindow::ButtonClicked() { QPushButton *Button = qobject_cast<QPushButton *> ( sender()); if (Button) { QString Text = Button->text(); qDebug() << "check" << Text; FinalFile.append(Text); // keep for later till we save ok ? Button->setEnabled(false); // Button->setStyleSheet(":enabled { color: " + foreground + "; background-color: " + color + "}"); // i dont know this one is correct or not } }
Say me some suggestions to set a color for disable buttons
thanks in advance ..@sankarapandiyan
take a look at this stylesheet example from the docu
https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qpushbuttonWhat is not listed, in the QPushButton section, but also applies to a QPushButton is the
disabled
identifier e.gQPushButton:disabled { background-color: black; }
example
int main(int argc, char *argv[]) { QApplication a(argc, argv); QPushButton btn; btn.resize(150,40); btn.show(); btn.setStyleSheet(QString("QPushButton:pressed{background-color: green;}" "QPushButton{background-color: red;}" "QPushButton:disabled{background-color:black;}")); QObject::connect(&btn, &QPushButton::clicked, [&btn]()->void{btn.setDisabled(true);}); return a.exec(); }