显示所有的qt控件api例程
时间: 2023-11-18 13:06:29 浏览: 90
当然,我可以为您提供一些常见的Qt控件API的例程。下面是一些常见的Qt控件及其使用方法的示例:
1. QLabel(标签):
```cpp
QLabel *label = new QLabel("Hello, World!", this);
label->setAlignment(Qt::AlignCenter);
label->show();
```
2. QPushButton(按钮):
```cpp
QPushButton *button = new QPushButton("Click me", this);
connect(button, &QPushButton::clicked, this, &MyClass::handleButton);
button->show();
```
3. QLineEdit(文本输入框):
```cpp
QLineEdit *lineEdit = new QLineEdit(this);
lineEdit->setPlaceholderText("Enter your name");
connect(lineEdit, &QLineEdit::returnPressed, this, &MyClass::handleReturnPressed);
lineEdit->show();
```
4. QComboBox(下拉列表):
```cpp
QComboBox *comboBox = new QComboBox(this);
comboBox->addItem("Option 1");
comboBox->addItem("Option 2");
comboBox->addItem("Option 3");
connect(comboBox, QOverload<int>::of(&QComboBox::activated), this, &MyClass::handleComboBoxActivated);
comboBox->show();
```
5. QRadioButton(单选按钮):
```cpp
QRadioButton *radioButton1 = new QRadioButton("Option 1", this);
QRadioButton *radioButton2 = new QRadioButton("Option 2", this);
QRadioButton *radioButton3 = new QRadioButton("Option 3", this);
QButtonGroup *buttonGroup = new QButtonGroup(this);
buttonGroup->addButton(radioButton1);
buttonGroup->addButton(radioButton2);
buttonGroup->addButton(radioButton3);
connect(buttonGroup, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), this, &MyClass::handleButtonGroupClicked);
radioButton1->show();
radioButton2->show();
radioButton3->show();
```
这只是一些常见的Qt控件的例程,您可以根据您的需求进一步探索Qt文档和示例代码。希望这些例子对您有所帮助!
阅读全文