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. How setCurrentIndex to none?
Forum Updated to NodeBB v4.3 + New Features

How setCurrentIndex to none?

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

    After deletion item in my QListView i want to set current index to NONE, it's automatically change it to next, but i want no item selected.

    Tried fill it with empty index(it's all my poor imagination capable for now)

    QModelIndex *noIndx = new QModelIndex();
    ui->listV->setCurrentIndex(noIndx);
    

    it rejects to compile because "want const model index, not this scum".

    UPDATE:

    Found:

    selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
    

    But it seems working but only apart. View works like nothing selected(which already good), but visually closest item still selected.

    JonBJ 1 Reply Last reply
    0
    • EngelardE Engelard

      After deletion item in my QListView i want to set current index to NONE, it's automatically change it to next, but i want no item selected.

      Tried fill it with empty index(it's all my poor imagination capable for now)

      QModelIndex *noIndx = new QModelIndex();
      ui->listV->setCurrentIndex(noIndx);
      

      it rejects to compile because "want const model index, not this scum".

      UPDATE:

      Found:

      selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);
      

      But it seems working but only apart. View works like nothing selected(which already good), but visually closest item still selected.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Engelard

      it rejects to compile because "want const model index, not this scum".

      void QAbstractItemView::setCurrentIndex(const QModelIndex &index) (http://doc.qt.io/qt-5/qabstractitemview.html#setCurrentIndex)

      So it takes a QModelIndex &, not a QModelIndex *:

      QModelIndex *noIndx = new QModelIndex();
      ui->listV->setCurrentIndex(*noIndx);
      

      or (simpler, no clean up):

      ui->listV->setCurrentIndex(QModelIndex());
      
      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