Search code examples
pythoncomboboxdropdownqtgui

Python QtGui Create drop down list with buttons


I have to create a drop down list in QtGui, and I need the option to click on the items.

I tried to use- QtGui.QComboBox(), but the items opened like comboBox- the selected item appear in the middle of the list and when the windows is small- I can't see all the items.

I tried also to create a class:

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        layout = QtGui.QHBoxLayout(self)
        self.button = QtGui.QToolButton(self)
        self.button.setPopupMode(QtGui.QToolButton.MenuButtonPopup)
        self.button.setMenu(QtGui.QMenu(self.button))
        self.textBox = QtGui.QTextBrowser(self)
        **self.textBox.append('test')**
        self.textBox.append(QtGui.QPushButton('sgd',clicked=self._toggle_set))#it is not working!!!
        action = QtGui.QWidgetAction(self.button)
        action.setDefaultWidget(self.textBox)
        self.button.menu().addAction(action)
        layout.addWidget(self.button)

but I could add only string items,

Any suggestions?

Thanks!


Solution

  • You can override the combobox stylesheet:

    combo.setStyleSheet("QComboBox { combobox-popup: 0; }")
    

    and it will show the items like drop-down list.