setCurrentIndex
时间: 2024-02-08 12:03:13 浏览: 44
setCurrentIndex is a method in Qt, a C++ GUI toolkit, used to set the current index of a QComboBox, QTabWidget or QStackedWidget.
In a QComboBox, setCurrentIndex sets the currently selected item in the dropdown list. In a QTabWidget, setCurrentIndex sets the currently visible tab. In a QStackedWidget, setCurrentIndex sets the currently visible widget.
The method takes an integer parameter, which represents the index of the item or widget to set as the current one. The index starts at 0 for the first item or widget and increases by 1 for each subsequent item or widget.
Example usage:
```
QComboBox *comboBox = new QComboBox();
comboBox->addItem("Item 1");
comboBox->addItem("Item 2");
comboBox->addItem("Item 3");
// sets the currently selected item to "Item 2"
comboBox->setCurrentIndex(1);
```
阅读全文