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;
}

 

posted @ 2019-05-23 12:10  夕西行  阅读(691)  评论(0编辑  收藏  举报