from PyQt5.QtWidgets import QApplication, QComboBox app = QApplication([]) combo = QComboBox() combo.addItem("Apple") combo.addItem("Banana") combo.addItem("Cherry") combo.adjustSize() combo.show() app.exec_()
from PyQt5.QtWidgets import QApplication, QWidget, QComboBox, QVBoxLayout app = QApplication([]) widget = QWidget() layout = QVBoxLayout() combo = QComboBox() combo.addItem("Small") combo.addItem("Medium") combo.addItem("Large") layout.addWidget(combo) widget.setLayout(layout) combo.adjustSize() widget.show() app.exec_()In this example, a combo box is added to a vertical layout within a widget. The adjustSize method is called to resize the combo box to fit the layout. Finally, the widget is shown. Package library: PyQt5.QtWidgets