MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QWidget *NewWin = new QWidget;
NewWin->resize(QSize(200,100));
//使输入框具有初始化提示语句
QLineEdit *MyEdit = new QLineEdit(NewWin);
MyEdit->setPlaceholderText("hello world");
//构建模糊查询对象
QStringList word_list;
word_list<<"Java"<<"C++"<<"C#"<<"PHP"<<"Perl"<<"Python"<<"Delphi"<<"Ruby";
QCompleter *MyInfor = new QCompleter(word_list);
//设置Eidt的模糊查询对象
MyEdit->setCompleter(MyInfor);
this->setCentralWidget(NewWin);
this->resize(QSize(400,500));
}
组合框案例:<基本上市一样的东西,有空多看看帮助文档>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPushButton *NewButton = new QPushButton(this);
NewButton->setText("hello");
NewButton->setGeometry(10,10,80,60);
NewButton->setStyleSheet("border: 3px solid red;border-radius:8px");
// NewButton->setStyleSheet("QPushButton:hover { color: white },QPushButton:!hover { color: red }");
QStringList word_list;
word_list<<"Java"<<"C++"<<"C#"<<"PHP"<<"Perl"<<"Python"<<"Delphi"<<"Ruby";
QCompleter *NewFind = new QCompleter(word_list);
ui->comboBox->setEditable(true);
ui->comboBox->setCompleter(NewFind);
}