QT 如何设置 QLineEdit 背景提示文字

设置QLineEdit背景提示文字:

ui->lineEditType->setPlaceholderText("请输入用户名");

设置背景提示文字的颜色或者字体大小:

ui->lineEditType->setStyleSheet("font-size:20px; color:rgb(0,160,230);");

在QLineEdit右侧添加按钮(比如选择文件按钮):

//
QPushButton *btn = new QPushButton;
btn->setText("#");
btn->setCursor(Qt::ArrowCursor);//设置按钮的鼠标样式
QWidgetAction *action = new QWidgetAction(ui->lineEditDllPath);
action->setDefaultWidget(btn);
ui->lineEditDllPath->addAction(action, QLineEdit::TrailingPosition);
//
connect(btn, &QPushButton::clicked, this, [=](){
    QString szPath = QFileDialog::getOpenFileName(NULL, "OPEN FILE", "./");
    if(szPath.isEmpty()){
        if(ui->lineEditDllPath->text().isEmpty()){
            QMessageBox::information(NULL, "INFO", "PATH EMPTY!");
        }
    }
    else{
        //显示文件路径到编辑框
        ui->lineEditDllPath->setText(szPath);
    }
});

你可能感兴趣的:(Qt,/,Qt,Creator,QLineEdit,setStyleSheet,QWidgetAction)