I have a PyQt5 app that has QDockWidgets on it's main window, and I have a menu that contain these dockwidgets listed. Whenever I click on a menu item, I want that widget to be closed or opened depending on whether the menu item is checked or not when I click it.
I check the menu items at init like this:
self.stream_action = QAction('Stream')
self.stream_action.setCheckable(True)
self.stream_action.setChecked(True)
self.stream_action.triggered.connect(self.show_hide_widget)
I do the same for the rest of them, and when the GUI starts it looks like this:
So when I click on one of them we jump to the show_hide_widget function, that looks like this:
def show_hide_widget(self):
widget_id = self.sender().text()
if self.sender().isChecked():
self.sender().setChecked(False)
if widget_id == 'Stream':
self.dock_stream.close()
else:
self.sender().setChecked(True)
if widget_id == 'Stream':
self.dock_stream.show()
But self.sender().isChecked() gives me False, why is that?