Reputation: 15
For example suppose I have this dictionary - dict = {a: 1,2,3, b: 4,5,6, c: 7,8,9}
how can I create combobox for dict with comboboxes for dict's values ?
Upvotes: 0
Views: 2779
Reputation: 37509
It sounds like you want a Nested Menu.
One way to do that in Qt is to use a QToolButton
with a QMenu
d = {'a': [1,2,3], 'b': [4,5,6], 'c': [7,8,9]}
button = QToolButton()
def callback_factory(k, v):
return lambda: button.setText('{0}_{1}'.format(k, v))
menu = QMenu()
for k, vals in d.items():
sub_menu = menu.addMenu(k)
for v in vals:
action = sub_menu.addAction(str(v))
action.triggered.connect(callback_factory(k, v))
button.setMenu(menu)
Upvotes: 3