Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a QPushButton disabled

Tags:

qt

I created lots of QPushButtons, added clicked signal and a slot name ´deneme()´ to all of the buttons with QT DESIGNER and the thing I want to do is; when I clicked any button, some operation should be done and lastly the button should be disabled but we do not know which button is clicked. I know I can disable the buttons with setEnabled() and isEnabled() but I do not know how to disable them.

like image 261
Cengaver Avatar asked Apr 19 '11 09:04

Cengaver


People also ask

What is the qpushbutton widget?

The QPushButton widget provides a command button. More... The push button, or command button, is perhaps the most commonly used widget in any graphical user interface. Push (click) a button to command the computer to perform some action, or to answer a question. Typical buttons are OK, Apply, Cancel, Close, Yes, No and Help.

How to convert qpushbutton to toggle button in Java?

Four QPushButton objects are defined as instance variables in the class. First button b1 is converted into toggle button by the statements − Clicked signal of this button is connected to a member method btnstate () which identifies whether button is pressed or released by checking isChecked () property.

How many qpushbutton objects are set with some of these attributes?

Four QPushButton objects are set with some of the above attributes. The example is written in object oriented form, because the source of the event is needed to be passed as an argument to slot function. Four QPushButton objects are defined as instance variables in the class. First button b1 is converted into toggle button by the statements −

Does setenabled (false) on a qpushbutton turn the text gray?

In Qt for Symbian, when I call setEnabled (false) on my QPushButton, I expected the button text to automatically turn gray. It does not.


1 Answers

If I understood correctly you connected various QPushButtons to the same slot. Inside of the slot deneme() you want to know which of the buttons was clicked. You can do something like:

  void deneme() {     QPushButton * b = qobject_cast<QPushButton *>(sender());     if (b) {        if (b == button1) { //button1 clicked            //doSomething();        }         else {           if (b == button2) {              //doSomething();           }        }        b->setEnabled(false);     }   } 
like image 143
bruno Avatar answered Sep 27 '22 19:09

bruno