Hi all, I am using PyQt.
In my UI, I have created a QDialogButtonBox that houses 3 buttons - 'Add', 'Remove' and 'Clear' and I assigned their roles as follows:
# List widget 01
# List widget 01
self.widget_01_btns = QtGui.QDialogButtonBox()
self.widget_01_btns.addButton('Add', QtGui.QDialogButtonBox.AcceptRole)
self.widget_01_btns.addButton('Remove', QtGui.QDialogButtonBox.RejectRole)
self.widget_01_btns.addButton('Clear', QtGui.QDialogButtonBox.ResetRole)
To copy to clipboard, switch view to plain text mode
As I will be having another same set of QDialogButtonBox, I thought it will be a good idea for them to 'share' the functions so that there is no need for me to write it twice.
However when I tried to connect the signals, the signal assigned for 'Clear' will be called whenever either 'Add' or 'Remove' button is used.
I tried another method that I found online, but upon using it, I got this error instead -
`AttributeError: 'NoneType' object has no attribute 'clicked'`
# For widget 01
self.widget_01_btns.accepted.connect(lambda:self.add_objects(self.widget01_list))
self.widget_01_btns.rejected.connect(lambda:self.remove_objects(self.widget01_list))
# This is called in conjunction whenever either 'Add' or 'Remove' button is clicked
self.widget_01_btns.clicked.connect(lambda:self.clear_objects(self.widget01_list))
# This is the online method I found but it is not working...
# self.widget_01_btns.button(QtGui.QDialogButtonBox.Reset).clicked.connect(lambda:self.clear_objects(self.widget01_list))
# For widget 01
self.widget_01_btns.accepted.connect(lambda:self.add_objects(self.widget01_list))
self.widget_01_btns.rejected.connect(lambda:self.remove_objects(self.widget01_list))
# This is called in conjunction whenever either 'Add' or 'Remove' button is clicked
self.widget_01_btns.clicked.connect(lambda:self.clear_objects(self.widget01_list))
# This is the online method I found but it is not working...
# self.widget_01_btns.button(QtGui.QDialogButtonBox.Reset).clicked.connect(lambda:self.clear_objects(self.widget01_list))
To copy to clipboard, switch view to plain text mode
Any pointers?
Bookmarks