Mahdi_Nine
Mahdi_Nine

Reputation: 14751

QPushButton and clicked slot

i have a verticalLayout that there's three labels with a button in each line. when i click on each button the event

button_clicked()
{

}

is firing. this event is for all button i.e when i click on each of button this function is called. now i want when i click on each button the same row that button is in that remove. how can i do that? first of all must be a unique value that i detect which button is clicked and second i must delete that row but i know how. any idea?

Upvotes: 0

Views: 325

Answers (1)

Re-answering, with the additional data provided at the comment:

You can connect all buttons to the same slot and then use the sender() method to identify who is triggering the signal:

void MyClass::button_clicked() {
    QAbstractButton* button = qobject_cast<QAbstractButton*>(sender());
    if ( !button ) {
        return; // not called from a button.
    }
    button->setText("Clicked");
}

Upvotes: 2

Related Questions