I am designing a widget which has a grid of buttons. When clicked I want these buttons to present the user with 3 choices (ideally in a small drop down menu) that they can select from. When they select 1 of the 3 choices, I want that button to be selected (i.e., remain depressed). I want the QAction that is associated with each of the 3 choices to be able to know which button was clicked so that I can log which button in the grid was clicked. Each button in the grid needs to be exclusive, and when selected. The 3 choices presented are the same for all buttons.
I first started with a QButtonGroup and QPushButtons in a QGridLayout. I was able to get the buttons to be exclusive as I wanted. When I changed the buttons from QPushButton to QToolButton, and added a drop down menu, two things happened:
- When they select an item from the menu, the button doesn't stay depressed like I want it to.
- I can't seem to see a way for the menu action to be informed about which button was selected, so I am unable to log which button is selected.
Any thoughts on how I can achieve the functionality I am looking for?
EDIT:
A few clarifying points:
- Each button in the m x n grid represents a person.
- The drop down list on each button lets you select what action that person is currently doing.
- Only one person can be doing something at a time. Hence, only one button in the entire grid can be depressed at a time.
- The items in the button drop down menu should become checked when they are selected, and these items need to be exclusive, so if a button is clicked twice, the a new checked menu item in the drop down menu should uncheck the previous one.
- When an item in the button drop down menu is selected, the menu should go away and the button should appear depressed.
- I need to log the button (i.e., the row and column) that was clicked as well as the choice selected from the button drop down menu. So somehow menu item signal/slot needs to know about which button was clicked. However, QToolButton::setMenu() doesn't transfer ownership of the Menu to the QToolButton, so I'm not sure how to make the signals/slots in the QActions of the QMenu aware of which button was selected.