It is not so simple, however it is doable. The problem is that when you click the button, the event event does not apply to the list widget. Therefore, you need to find a way to propagate the signal back to the list widget.
When the button is pressed, a pressed signal is issued. When it is released, the released signal is emitted. I will show you how to do this for one of them, you must do the same for the other.
The easiest way to do what you want is to add a connection between the pressed button signal and the slot that will change the background of your list. You have a QListWidget that has some UserDetails widgets, each of which has a QPushButton . So we have to go all the way from QPushButton to QListWidget .
In your UserDetails class UserDetails create a new signal, for example buttonPressed() , and connect the pressed() button to it. Thus, every time a button is pressed on your widget, the widget itself will notify the world that its button has been pressed.
connect(ui->button, SIGNAL(pressed()), this, SIGNAL(buttonPressed())
Now we want to notify QListWidget that the button is pressed. To do this, we need to connect the buttonPressed signal from UserDetails using the slot, let us call the buttonPressedSlot() slot
connect(myItem, SIGNAL(pressed()), this, SLOT(buttonPressedSlot())
Now the slot should determine what the sender is (since all UserDetails will be connected to the same slot, find the corresponding QListWidgetItem and call the slot that will update the background of this element.
void LiwstWidgetClick::buttonPressedSlot() { QObject* signalSender = QObject::sender(); UserDetails* p = qobject_cast<UserDetails *>(signalSender); if (p == NULL) return;
You must do the same for the released() signal.
EDIT
If the button was public, you can avoid an additional signal, for example, if you had a function ( getButton() ) in UserDetails that returned ui->button , you could only have one connection
connect(myItem->button(), SIGNAL(pressed()), this, SLOT(buttonPressedSlot()));
EDIT 2
If you just want to change the background of your button when pressed, you can achieve this using stylesheets . You need entries in your stylesheet for the normal state of the button and for the state pressed . The list of available states looks here . Sample code follows
QListView QPushButton { color: grey; border-image: url(/path/to/image1) 3 10 3 10; } QListView QPushButton:pressed { color: red; border-image: url(/path/to/image2) 3 10 3 10; }
Note that I use the QListView Descendant Selector to get only these QPushButtons , which are children of the QListView