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. QComboBox with QCompleter, lineedit -> selectAll

QComboBox with QCompleter, lineedit -> selectAll

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.2k 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.
  • the_T Offline
    the_T Offline
    the_
    wrote on last edited by
    #1

    Hi all,

    For a large dropdown (250+ items) I used QCompleter for a searchable QCombobox. Searching and autocompletion works fine, but now I want to select all text when I click in the textfield.

    As far as I correctly understand http://doc.qt.io/qt-5/qlineedit.html#selectAll , the text is highlighted and deleted if I start typing.

    To use it I installed an event filter on the QLineEdit

    //thiscombo is a valid QWidget
    QLineEdit *le = new QLineEdit(thiscombo);
    le->setObjectName("Completer_1206");
    le->installEventFilter(this);
    apcompleter = new QCompleter(le);
    connect(apcompleter,SIGNAL(activated(QString)),this,SLOT(completerslot(QString)));
    thiscombo->setLineEdit(le);
    thiscombo->setAutoCompletion(false);
    thiscombo->setInsertPolicy(QComboBox::NoInsert);
    le->setCompleter(apcompleter);
    apcompleter->setCaseSensitivity(Qt::CaseInsensitive);
    apcompleter->setCompletionMode(QCompleter::PopupCompletion);
    apcompleter->setModel(new QStringListModel(thiscombo));
    
    //inside the ::eventFilter(QObject,QEvent)
    if(object->objectName() == "Completer_1206" && event->type() == QEvent::MouseButtonPress) {
            qDebug() << object;
            QLineEdit *l = dynamic_cast<QLineEdit *>(object);
            l->selectAll();
            qDebug() <<l->selectedText() << l->hasSelectedText();
    
    
        }
    

    So on MouseClick I get the selectedText and hasSelectedText is true, but the text is not highlighted, and when i start typing, the text is inserted at the cursor position.

    Is there anything wrong in the way I try to highlight the text?

    Thanks in advance

    -- No support in PM --

    1 Reply Last reply
    0
    • the_T Offline
      the_T Offline
      the_
      wrote on last edited by
      #2

      Well the solution is very simple.

      The last line in my eventFilter is

      QWidget::eventFilter(object,event);
      

      So it also does what the widget usually does on mouse click.

      a simple

      return true;
      

      at the end of my if and the text is highlighted.

      -- No support in PM --

      1 Reply Last reply
      3

      • Login

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