Nominate our 2022 Qt Champions!

Make some text in QLineEdit read-only/uneditable?

  • I have a QLineEdit that currently contains the date and time. This particular line edit is where the user will enter comments. So when the program starts, the QlineEdit will already have "Nov 08 2015 14:13:30 " and when the user clicks on the lineedit, I want the text cursor to start right after time and make the date/time uneditable.

    QDate date = QDate::currentDate();
    QTime time = QTime::currentTime();
    ui->comment->setText(date.toString("MMM dd yyyy")+" "+time.toString("hh:mm:ss"));
    bool function1::eventFilter(QObject *obj, QEvent *ev)
       if(obj == ui->comment && ev->type() == QEvent::MouseButtonPress)

Log in to reply