QComboBox control
1. Add content:
//不带图标写法
ui->comboBox->addItem("A1");
ui->comboBox->addItem("A2");
ui->comboBox->addItem("A3");
ui->comboBox->addItem("A4");
ui->comboBox->addItem("A5");
ui->comboBox->addItem("A6");
//带图标写法
ui->comboBox->addItem(icon,QString::asprintf("Item %d",i));
//可以使用QStringList 一次写入多个数据
QStringList strList;
strList<<"A1"<<"A2"<<"A3"<<"A4"<<"A5"<<"A6";
ui->comboBox->addItems(strList);
2. Default display
ui->comboBox->setCurrentIndex(2); //后面的数字是显示第几个,从零开始
3. Get the currently selected index of the comboBox control
//索引为0-5
int index = ui->comboBox->currentIndex();//获得索引
QString StrIntN=QString::number(index);
QMessageBox::information(this, "comboBox", StrIntN, QMessageBox::Ok);
4. Get the current content
QMessageBox::information(this, "comboBox", ui->comboBox->currentText(), QMessageBox::Ok);
5. Clear the list
ui->comboBox->clear(); //清除列表
QLineedit
1. QLineedit’s 6 signals and slot functions
void cursorPositionChanged(int old, int new) | The cursor position changes and a signal is emitted. The previous position is old, and the new position is new. |
---|---|
void editingFinished( ) | When editing is completed, click Enter to emit a signal. |
oid returnPressed( ) | The cursor clicks Enter in the line editing box to emit a signal. |
void selectionChanged( ) | Emits a signal when the selected text changes. |
void textChanged(const QString & text) | Emit a signal when the text content changes. |
void textEdited(const QString & text) | This signal is emitted when text is edited. When the text is changed using setText(), the textEdited() signal is also emitted. |
2. Commonly used class member functions
void setPlaceholderText(QString) | Set placeholder |
---|---|
void setText(QString) | Set the text in the edit box |
void setReadOnly(bool) | Set the edit box to read-only mode and cannot edit it. |
void setEnabled(bool) | Set whether to activate the line edit box, the function is similar to 3 |
bool isModified() | Determine whether the text has been modified |
void selectAll() | Select all text in the box |
QString displayText() | Returns the displayed text |
QString selectedText() | Returns the selected text |
QString text() const | Returns the current text of the input box |
void setMaxLength(int) | Set the maximum allowed length of text |
3. Set text alignment
lineedit->setAlignment(Qt::AlignLeft)//左对齐
lineedit->setAlignment(Qt::AlignRight)//右对齐
lineedit->setAlignment(Qt::AlignCenter)//居中对齐
4. Get the input value
ui->lineEdit->text();//获取输入的值
5. Settings cannot be edited
setReadOnly(false);
//或
setEnabled(false);
//或
setFocusPolicy(Qt::NoFocus);//无法获得焦点,自然无法输入,其他文本控件类似
//或
hasAcceptableInput(false);
6. Set the maximum number of characters that can be entered
setMaxLength()
QTabWidget control
1. Set the page name
ui->tabWidget->setTabText(0,"常规");
ui->tabWidget->setTabText(1,"安全");
ui->tabWidget->setTabText(2,"属性修改");
ui->tabWidget->setTabText(3,"详细信息");
ui->tabWidget->setTabText(4,"以前的版本");
2. Set prompt information
ui->tabWidget->setTabToolTip(0,"常规页面提示信息");
ui->tabWidget->setTabToolTip(1,"安全页面提示信息");
ui->tabWidget->setTabToolTip(2,"属性修改页面提示信息");
ui->tabWidget->setTabToolTip(3,"详细信息页面提示信息");
ui->tabWidget->setTabToolTip(4,"以前的版本提示信息");
3. Setting page activation
ui->tabWidget->setTabEnabled(0, true);
ui->tabWidget->setTabEnabled(1, true);
ui->tabWidget->setTabEnabled(2, true);
ui->tabWidget->setTabEnabled(3, true);
ui->tabWidget->setTabEnabled(4, false);
4. Set the title bar position
//设置标题栏位置 North, South, West, East
ui->tabWidget->setTabPosition(QTabWidget::West);
5. Set the close button
//设置页面关闭按钮。
ui->tabWidget->setTabsClosable(true);
6. Clear all pages
qDebug() << "清空所有页面!";
ui->tabWidget->clear();
7. Delete a page
qDebug() << "删除页面!";
ui->tabWidget->removeTab(4);
Continuously updating...