Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QLineEdit: selectAll() selects text but does not show any visible selection (Embedded Linux)
Forum Updated to NodeBB v4.3 + New Features

QLineEdit: selectAll() selects text but does not show any visible selection (Embedded Linux)

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 4 Posters 7.3k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    Bubbas
    wrote on 22 Nov 2011, 11:05 last edited by
    #1

    Hi all,

    I have a problem regarding the QLineEdit in an embedded linux application:
    I want to programatically set the default text in a QLineEdit and also have it selected and as such be visibly selected (e.g marked with "selection-background-color" and "selection-color" as defined in the style sheet).
    So, I use the selectAll() function of the QLineEdit.

    The problem is that the text seems to be selected, as the hasSelectedText() function returns true and the selectedText() returns the correct text. However, the text is not marked as selected.

    If I then (via the touch screen) select the QLineEdit the text appears selected. BUT, if I then start to type the default text
    does not get deleted but the new text is appended at the end. Shouldn't the marked text get deleted by default in this case?

    I have looked at and used mr. Volker's suggestion as described here:

    "http://developer.qt.nokia.com/forums/viewthread/8590":http://developer.qt.nokia.com/forums/viewthread/8590

    but the problem still remains.

    So, my questions is: How do I programatically set a default text in a QLineEdit and make it selected in code and visibly selected to the user without having to manually (via mouse, keyboard or touchscreen) select the QLineEdit??

    Best Regards,
    Bubbas

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rebell
      wrote on 16 Apr 2012, 22:00 last edited by
      #2

      Did you find a solution? I have the same problem on not embedded Linux (Ubuntu 11.10, Gnome 3).

      @
      _view.label->installEventFilter(this);
      @

      @
      bool SecretForm::eventFilter(QObject* obj, QEvent* event) {
      if (obj == _view.label) {
      if (event->type()== QEvent::FocusIn) {
      if (_view.label->text() == DEFAULT_SECRET_LABEL) {
      _view.label->selectAll();
      qDebug() << _view.label->hasSelectedText();
      //_view.label->setSelection(0,_view.label->text().length()-1);
      //return true;
      }
      }
      }
      //return true;
      }
      @

      Just prints: "true". No selection visible.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Aleksandar
        wrote on 16 Nov 2012, 13:15 last edited by
        #3

        All you need to do is to put those lines at the end, after you set all other widgets..
        lineEdit->selectAll()
        lineEdit->setFocus()

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mccombbj
          wrote on 1 Apr 2015, 15:52 last edited by
          #4

          I know this thread is old, but some of us are still stuck with QT 4.8.4 (QWS) in embedded. I spent some time trying to figure out how to selectAll on a lineEdit that was setup via a UI file.

          I tried the following, but it didn't work . ( note it does work when I build for desktop )
          ui->lineEdit->selectAll();
          ui->lineEdit->setFocus();
          Then I noticed If I pressed the line edit then ran the selectAll() it worked.
          So if you force a mouse press event for the widget, it forces focus and hence will let you selectALL().
          QEvent eventPress( QEvent::MouseButtonPress );
          QEvent eventRelease( QEvent::MouseButtonRelease );
          QApplication::sendEvent( ui->lineEdit , &eventPress ); // simulate a mouse press
          QApplication::sendEvent( ui->lineEdit , &eventRelease ); // simulate a mouse release
          ui->lineEdit->selectAll();

          This worked for me, I hope it can get someone else out of a bind too.
          I'm posting this because I didn't see any other examples of people with this work around.

          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