QComboBox* myComboBox = new QComboBox(); myComboBox->addItem("Option 1"); myComboBox->addItem("Option 2"); myComboBox->addItem("Option 3"); QLabel* myLabel = new QLabel("Selected option:"); connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateLabel(int))); void MyClass::updateLabel(int index) { myLabel->setText("Selected option: " + myComboBox->itemText(index)); }
QStringList myList = {"Option 1", "Option 2", "Option 3"}; QComboBox* myComboBox = new QComboBox(); myComboBox->addItems(myList); QListWidget* myListWidget = new QListWidget(); myListWidget->addItems(myList); connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(filterList(int))); void MyClass::filterList(int index) { QString selectedOption = myComboBox->itemText(index); for(int i=0; iThis example creates a QComboBox widget with the same options as a QListWidget. Whenever the user selects a different option in the dropdown list, the filterList() function is called, which filters the items in the QListWidget based on the selected option. Package library: Qtcount(); i++) { QString listItem = myListWidget->item(i)->text(); if(listItem.contains(selectedOption)) myListWidget->item(i)->setHidden(false); else myListWidget->item(i)->setHidden(true); } }