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. Refreshing QTableView selection manually
Qt 6.11 is out! See what's new in the release blog

Refreshing QTableView selection manually

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.5k 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.
  • Lefix2L Offline
    Lefix2L Offline
    Lefix2
    wrote on last edited by Lefix2
    #1

    Hello,
    I have a probleme with a qTableview.
    I have two widgets, a qCustomPlot and a qTableView between wich selections signals are sent.
    For the uses of my application, i was forced to blockSignal on my SelectionModel's TableView and modify the selection manually.
    But, when i select my indexes, if there is no scroll, the olds selected lines doesn't deselect until user get focus on qTableView or until the QTableView is resized/scrolled.
    I tried update(), repaint() and show() on mys tableView but nothing changed! :/

    Here is the code:

    void OSGM::onGraphSelectionChanged(int index)
    {
        auto selectionModel = m_TableView.selectionModel();
        QItemSelection selection;
        selectionModel->blockSignals(true);
    
            // if it's a selection
            if (index != OSGEH::ELEMENT_DESELECTED) {
                // create the selection manually
                auto keys = m_TabRectMap.keys(index);
    
                for (auto key : keys) {
                    auto row = m_TableView.model()->index(key, 0);
                    selection.append(QItemSelectionRange(row, row));
                }
            }
            selectionModel->select(selection, QItemSelectionModel::Current | QItemSelectionModel::Rows);
        
         selectionModel->blockSignals(false);
    
        if (selection.size() != 0) 
        {
            // scroll qtableview to the first item
            m_TableView.scrollTo(selection.at(0).bottomRight(),QAbstractItemView::PositionAtTop);
        }
        m_TableView.show();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Why do you need to call blockSignals ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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