简体   繁体   English

QPushButton并点击了插槽

[英]QPushButton and clicked slot

i have a verticalLayout that there's three labels with a button in each line. 我有一个verticalLayout ,有三个标签,每行有一个按钮。 when i click on each button the event 当我点击每个按钮时的事件

button_clicked()
{

}

is firing. 正在开火。 this event is for all button ie 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? 任何想法?

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: 您可以将所有按钮连接到同一个插槽,然后使用sender()方法识别触发信号的人:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM