Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Make some text in QLineEdit read-only/uneditable?
Qt 6.11 is out! See what's new in the release blog

Make some text in QLineEdit read-only/uneditable?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 712 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    marlenet15
    wrote on last edited by marlenet15
    #1

    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"));
    ui->comment->installEventFilter(this);
    
    bool function1::eventFilter(QObject *obj, QEvent *ev)
    {
       if(obj == ui->comment && ev->type() == QEvent::MouseButtonPress)
       {
        ui->comment->setCursorPosition(????);
       }
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved