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 to know user select item by mouse move?

How to know user select item by mouse move?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 438 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.
  • qazaq408Q Offline
    qazaq408Q Offline
    qazaq408
    wrote on last edited by
    #1

    Qt5.15+vs2019

    QTableView + model

    The step:

    1. MouseClicked in QModelIndex(0,0)
    2. move mouse
    3. MouseRelease in QModelIndex(0,3)

    Now ,there are four items in the first column is actived(Maybe selected,i just know the background-color of these item is blue,and the other is white). So I want to know which items are selected.

    The first ,i use SIGNAL actived(const QModelIndex),but the SLOT can't receive any index.

    And then i try to inherit QTableView and reimplement MouseEvent,it looks like

    void MyTableView::mouseReleased(QMouseEvent event){
        //How to find all item that choosed by MouseMove?
        event->accept();
    }
    

    Do you have any better idea?

    JonBJ 1 Reply Last reply
    0
    • qazaq408Q qazaq408

      Qt5.15+vs2019

      QTableView + model

      The step:

      1. MouseClicked in QModelIndex(0,0)
      2. move mouse
      3. MouseRelease in QModelIndex(0,3)

      Now ,there are four items in the first column is actived(Maybe selected,i just know the background-color of these item is blue,and the other is white). So I want to know which items are selected.

      The first ,i use SIGNAL actived(const QModelIndex),but the SLOT can't receive any index.

      And then i try to inherit QTableView and reimplement MouseEvent,it looks like

      void MyTableView::mouseReleased(QMouseEvent event){
          //How to find all item that choosed by MouseMove?
          event->accept();
      }
      

      Do you have any better idea?

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

      @qazaq408
      Before you go anywhere near mouse move/click, why aren't you using the item selection model, like void QTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) or (preferable) the signal void QItemSelectionModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) on the table view's QItemSelectionModel *QAbstractItemView::selectionModel() const?

      qazaq408Q 1 Reply Last reply
      1
      • HansonH Offline
        HansonH Offline
        Hanson
        wrote on last edited by
        #3

        @qazaq408
        You can use QItemSelectionModel to get selected items, just like this

        QModelIndexList indexList = tableView->selectionModel()->selectedIndexes();
        

        https://doc.qt.io/qt-6/qitemselectionmodel.html#selectedIndexes
        https://doc.qt.io/qt-6/qitemselectionmodel.html#selectedColumns
        https://doc.qt.io/qt-6/qitemselectionmodel.html#selectedRows

        “Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.”
        —— Martin Golding

        1 Reply Last reply
        1
        • JonBJ JonB

          @qazaq408
          Before you go anywhere near mouse move/click, why aren't you using the item selection model, like void QTableView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) or (preferable) the signal void QItemSelectionModel::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) on the table view's QItemSelectionModel *QAbstractItemView::selectionModel() const?

          qazaq408Q Offline
          qazaq408Q Offline
          qazaq408
          wrote on last edited by
          #4

          @JonB

          THAKN YOU!

          You save me !

          1 Reply Last reply
          0
          • qazaq408Q qazaq408 has marked this topic as solved on

          • Login

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