[SOLVERD] QVector of QPushButton and slots, events

  • Hello,
    I have dynamic array of buttons, labels and so on. Number of those depends on user input. Unfortunately each of buttons is doing something else. Number of buttons is 1-16. I may just make 16 slots and just do not connect all, but is there any way to do it with events? I tried but hitbutton() is protected and isDown is not working...
    @void Test::mousePressEvent(QMouseEvent *event){
    for(int i =0;i<buttons.size();i++){
    // if(buttons.at(i)->hitButton(QCursor::pos())){
    } else {

  • Not 100% clear what you want to do, but maybe this helps:
    sender() returns the QObject that caused a slot to be called (via a signal). So you could connect all buttons to the same slot and distinguish the buttons in there via qobejct_cast<QPushButton*>(sender()).

  • Thanks! It works!

    @void Test::buttonAction(){
    for(int i=0;i<buttons.size();i++){

Log in to reply