11、LineEdit与setCompleter自动补全
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug>//引入打印 #include <QCompleter> //自动补全(完成、完善的意思) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //内容 ui->lineEdit->setText("Text"); QString str=ui->lineEdit->text(); qDebug()<<str; //左间距 ui->lineEdit->setTextMargins(10,0,0,0); //提示文本功能 QStringList sList; sList<<"hello"<<"Here"<<"home";//类似cin QCompleter *com=new QCompleter(sList,this); com->setCaseSensitivity(Qt::CaseInsensitive);//不区分大小写 ui->lineEdit->setCompleter(com);//设置自动补全 } MainWindow::~MainWindow() { delete ui; }