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. QTableView selects items not having flag Qt::ItemIsSelectable
Forum Updated to NodeBB v4.3 + New Features

QTableView selects items not having flag Qt::ItemIsSelectable

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 936 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.
  • N Offline
    N Offline
    nullptr
    wrote on last edited by
    #1

    Hello! We have a QTableView connected to a custom model derived from QStandardItemModel. This model is pretty normal: rows consisting of a fixed number of columns. However one of the columns has removed the Qt::ItemFlag Qt::ItemIsSelectable. But the QTableView continues to select items in this column, both visually and functionally (the view's selection model emits signal QItemSelectionModel::selectionChanged()with corresponding model index). The non-selectable item is selected both with selection behavior SelectItems and SelectRows.

    Is this correct behavior of QTableView? Why doesn't the standard widget QTableView respect the item's properties in the underlying model?

    I just want to catch clicks on these items (this column) using QAbstractItemView::clicked(), but I don't want to change the selection or change the focus (set new current item for the view). Is this possible?

    JonBJ 1 Reply Last reply
    0
    • N nullptr

      Hello! We have a QTableView connected to a custom model derived from QStandardItemModel. This model is pretty normal: rows consisting of a fixed number of columns. However one of the columns has removed the Qt::ItemFlag Qt::ItemIsSelectable. But the QTableView continues to select items in this column, both visually and functionally (the view's selection model emits signal QItemSelectionModel::selectionChanged()with corresponding model index). The non-selectable item is selected both with selection behavior SelectItems and SelectRows.

      Is this correct behavior of QTableView? Why doesn't the standard widget QTableView respect the item's properties in the underlying model?

      I just want to catch clicks on these items (this column) using QAbstractItemView::clicked(), but I don't want to change the selection or change the focus (set new current item for the view). Is this possible?

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

      @nullptr said in QTableView selects items not having flag Qt::ItemIsSelectable:

      The non-selectable item is selected both with selection behavior SelectItems and SelectRows.

      Qt::ItemIsSelectable flag only refers to (allowing/preventing) user-selectable (e.g. by clicking), not programmatic selectable. So how is the selection happening?

      1 Reply Last reply
      2
      • N Offline
        N Offline
        nullptr
        wrote on last edited by
        #3

        Yes, Qt::ItemIsSelectable affects user selection (view), i.e. if I click a table cell and selection behavior is SelectRows, the view will select the row containing that cell. But then the selection will also contain the item with no flag Qt::ItemIsSelectable which I find strange. The selection will also happen with selection behavior SelectItems. It seems that QTableView ignores the non-selectable property of the underlying item when it presents the data model for the user.

        Is this a bug or a feature?

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nullptr
          wrote on last edited by nullptr
          #4

          Sorry, it turns out that our model was wrapped in a QSortFilterProxyModel which overrided the flags() method. I didn't know this. This reimplementation ignored the actual item flag in the wrapped model. Now I can see that QTableView is working as it should :)

          QTableView still changes focus (changes current index) when any cell is clicked. Not sure if this can be prevented, I'll take a look.

          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