How to unclick a QPushButton
Solved
General and Desktop
-
i am able to click a push button but not able to unclick it.This line button->setDown(false); does not unclick the button,
bool eventFilter(QObject* obj, QEvent* event) { if (obj->isWidgetType()) { // Check if the event is a KeyPress or KeyRelease if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); // Check if Ctrl is pressed (Ctrl key is Qt::ControlModifier) if (keyEvent->modifiers() == Qt::ControlModifier) { // Check if the QColorDialog is currently open QColorDialog* colorDialog = qobject_cast<QColorDialog*>(obj); if (colorDialog) { // Find the "Pick Screen Color" button and click it programmatically QList<QPushButton*> buttons = colorDialog->findChildren<QPushButton*>(); for (QPushButton* button : buttons) { if (button->text().contains("Pick Screen Color", Qt::CaseInsensitive)) { button->click(); break; } } } } } else if (event->type() == QEvent::KeyRelease) { QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event); // Check if Ctrl is released (Ctrl key is Qt::ControlModifier) if (keyEvent->key() == Qt::Key_Control) { // Check if the QColorDialog is currently open QColorDialog* colorDialog = qobject_cast<QColorDialog*>(obj); if (colorDialog) { // Find the "Pick Screen Color" button and uncheck it programmatically QList<QPushButton*> buttons = colorDialog->findChildren<QPushButton*>(); for (QPushButton* button : buttons) { if (button->text().contains("Pick Screen Color", Qt::CaseInsensitive)) { // Uncheck the button if it is checked (simulate unclicking) button->setDown(false); break; } } } } } } }
-
What are you trying to achieve? Click a button? See https://doc.qt.io/qt-6/qabstractbutton.html#click
-
@Christian-Ehrlicher i want to unclick the pick screen color button after it has been clicked , currently i am not able to do it with code.
I need to manually click once with the mouse to unclick it.
-
Why do you want to do this? I would guess it's a button with checkable property so you have to reset this. Simply look in the source code to see if I'm correct.
-
@Christian-Ehrlicher This is not a checkable button.
-