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. QCompleter::currentIndex issue
Forum Updated to NodeBB v4.3 + New Features

QCompleter::currentIndex issue

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.8k 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.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    Hi,

    I set QCompleter to QLineEdit object... it works fine but I can't get the current index from QCompleter by currentIndex() because it always return 0 for row index.

    PS
    I call currentIndex() from QLineEdit editingFinished() slot.
    @void MainWindow::on_lineEdit_find_editingFinished()
    {
    if (p_db.isOpen()) {
    /*! \bug Set current row from the completer
    */
    ui->tableView_table->setCurrentIndex(completer->currentIndex());
    qDebug() << completer->currentIndex().row();
    }
    }@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbnoimi
      wrote on last edited by
      #2

      Bump it :)

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bodzio131
        wrote on last edited by
        #3

        Hi,

        First of all currentIndex returns index from 'completion model', which is filtered model containing "all the possible matches for the current completion prefix" (see QCompleter doc).
        Let say you have list a,b,c and you type a. This way your completion model contains only one element.
        Let say you have a,b,bc and you type b, then you will get model with two elements.

        Second thing is that editingFinished signal seems to be too late to read this info. Make completer with a,b,bc and choose bc, surprisingly you will get b in editingFinished slot either as index or string.
        You could use QCompleter::activated signal to get which string/index was activated. But still, you will get index from current completion list, not from whole model.

        I'm wondering if 'completion model' is QAbstractProxyModel as it presents filtered content. If yes then you could use mapToSource to get index for full model. However, this would be workaround as you need to cast completion model into QAbstractProxyModel.

        Best regards.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbnoimi
          wrote on last edited by
          #4

          [quote author="Bogdan" date="1366753014"]Second thing is that editingFinished signal seems to be too late to read this info. Make completer with a,b,bc and choose bc, surprisingly you will get b in editingFinished slot either as index or string.
          You could use QCompleter::activated signal to get which string/index was activated. But still, you will get index from current completion list, not from whole model.[/quote]

          This is absolutely correct because this will give wrong index. I've to get the index from the whole model not from the completer model. so do you know how I can get the real index (from the whole model) of the chose item by completer?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bodzio131
            wrote on last edited by
            #5

            As I said, you could try to cast QCompleter::completionModel() into QAbstractProxyModel (assuming completion model is QAbstractProxyModel, I didn't check this) and use QAbstractProxyModel::mapToSource. This way you would get index from the whole model. However, I see casting as sign of wrong project, so I wouldn't do it myself.
            Another way is to just search whole QCompleter::model() for completion string. Not very stylish but should work ;)

            1 Reply Last reply
            0
            • U Offline
              U Offline
              username31480
              wrote on last edited by
              #6

              A bit late here, but this was a top google response when I had the same issue.

              A clean and elegant solution I found was to use QCompleter::popup(), which is a QAbstractItemView*, then used QAbstractItemView::currentIndex().
              This method was used to get the user selected model index after QLineEdit::editingFinished() signal.

              My QCompleter was assigned a QTableView popup widget upon construction; I do not know if that is what enabled getting a currentIndex by way of the popup() QAbstractItemView....

              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