Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVERD] QVector of QPushButton and slots, events
QtWS25 Last Chance

[SOLVERD] QVector of QPushButton and slots, events

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pepek
    wrote on last edited by
    #1

    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(event->button()==Qt::LeftButton){
    // if(buttons.at(i)->hitButton(QCursor::pos())){
    if(buttons.at(i)->isDown()){
    labels.at(i)->setText("Click!");
    }
    } else {
    QWidget::mousePressEvent(event);
    }
    }
    }@

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      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()).

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pepek
        wrote on last edited by
        #3

        Thanks! It works!

        @void Test::buttonAction(){
        for(int i=0;i<buttons.size();i++){
        if(qobject_cast<QPushButton*>(sender())==buttons.at(i)){
        labels.at(i)->setText("Boom");
        }
        }
        }@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved