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. QTreeView + sort model + QStandardItemModel, the most efficient way to update the model?
Forum Updated to NodeBB v4.3 + New Features

QTreeView + sort model + QStandardItemModel, the most efficient way to update the model?

Scheduled Pinned Locked Moved General and Desktop
23 Posts 3 Posters 18.0k Views 2 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.
  • V Violet Giraffe

    @antis said:

    Right, but QAbstractItemView has:

    tableView->setSelectionBehaviour( QAbstractItemView::SelectRows );
    

    That it does! And like I said, I have set this option. the table view does select a whole row, but it does not span the cursor across the whole row. While the tree view does both no problem.

    A Offline
    A Offline
    antis
    wrote on last edited by
    #21

    That it does! And like I said, I have set this option. the table view does select a whole row, but it does not span the cursor across the whole row. While the tree view does both no problem.

    Got me. The dotted rectangle's shows the editing focus. Logically, the focus lies always on the focused table cell. In a QTreeView on the other hand, it lies on the the tree item. You can paint the focus rect over the whole table row by overriding "QTableView::paint".

    1 Reply Last reply
    0
    • A Offline
      A Offline
      antis
      wrote on last edited by antis
      #22

      First, the table view is what you want for your use case. So please don't switch the view.

      Ok, I did some further research:
      My default file manager (and the file dialogs itself) display the focus around the item in the first column. This makes total sense, as this is the only editable column (the file name). The flag is defined in QAbstractTableModel::flags, which you need to override:

      Qt::ItemFlags MyTableModel::flags(const QModelIndex & index) const {
        if (index.column() > 0) {
          // remove focusable flag for all columns > 0
          return QAbstractTableModel::flags(index) & ~Qt::ItemIsEditable;
        }
      
        return QAbstractTableModel::flags(index);
      }
      

      EDIT: Corrected the code snippet.

      1 Reply Last reply
      2
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #23

        Thanks. This is counter-intuitive, but as long as I can fix it reliably for all platforms with 3 lines of code - why not. I've already reverted the change from QtreeView to QTableView under the pressure of the issues, but it won't take too long to try again.

        Filling QTableView is about twice as fast as QtreeView, so that's a good incentive, but the QtreeView definitely looks better on Windows (more native). At least so far. For example, the selection style is much different.

        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