Note that there are some explanatory texts on larger screens.

plurals
  1. POmaking a QToolButton checked with a QMenu
    text
    copied!<p>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.</p> <p>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:</p> <ul> <li>When they select an item from the menu, the button doesn't stay depressed like I want it to.</li> <li>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.</li> </ul> <p>Any thoughts on how I can achieve the functionality I am looking for?</p> <p>EDIT:</p> <p>A few clarifying points:</p> <ul> <li>Each button in the m x n grid represents a person.</li> <li>The drop down list on each button lets you select what action that person is currently doing.</li> <li>Only one person can be doing something at a time. Hence, only one button in the entire grid can be depressed at a time.</li> <li>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. </li> <li>When an item in the button drop down menu is selected, the menu should go away and the button should appear depressed.</li> <li>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.</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload