QT中使用Qcombox和QCompleter实现可编辑的combox下拉提示,并设置样式

QT中有一个QCompleter控件,这个控件可以绑在所有的输入控件上,用来下拉提示信息。

不废话直接上分代码:    

        QStringList strings;
        QComboBox *comboBox = new QComboBox();
        strings << "Biao" << "Biao Huang" << "Mac" << "MacBook" << "MacBook Pro" << "Mac Pro"; 
 
      comboBox->addItems(strings);  
      comboBox->setEditable(true);  

       completer = new QCompleter(strings, this);
        completer->setCompletionMode(QCompleter::UnfilteredPopupCompletion);
        //设置下拉提示popup的样式
       completer->popup()->setStyleSheet("    background-color: #294662;\
                                        color: #ffffff;\
                                        border: 1px solid #375C80;\
                                        border-radius: 5px;\
                                        padding: 0px 0px 0px 0px;\
                                        min-width: 17px;\
                                        font: 14px \"Arial\";");        

        ui->comboBox->setCompleter(completer);//绑定completer到combobox


 
  

你可能感兴趣的:(QT中使用Qcombox和QCompleter实现可编辑的combox下拉提示,并设置样式)