In my application a user is able to select a comport from a list of all available comports. This is to be done in a menu that is populated with QAction widgets. However, the current code does not show which port has been selected, and in order to make the application more intuitive, I would like to indicate which port has been selected, thus showing the user what state the program is in. By including some sort of icon (like a check mark, for example) in the menu right next to the selected port, it would be obvious which port has been selected. What is the correct way to do this?
My code:
# Populate the serial port menu with all the available ports.
for port in comports():
_port = QtWidgets.QAction(port[0], mainWindow)
_port.setCheckable(True) # WRONG!
self.menuChoose_port.addAction(_port)
_port.triggered.connect(self.comportSelect)
This code obviously doesn't do what I want, because it puts checkboxes next to each menu item. Additionally, it allows the user to check more than one comport at time, which is not at all desirable.