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. QHeaderView drag & drop, with a Model
Forum Updated to NodeBB v4.3 + New Features

QHeaderView drag & drop, with a Model

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.2k 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.
  • G Offline
    G Offline
    gaijinpunch
    wrote on last edited by
    #1

    I think I'm missing something fundamental about dragging and dropping columns. My basic setup is

    QAbstractItemModel -> QSortFilterProxyModel -> QTableView -> QHeaderView.
    All are subclassed

    @
    void my_header::set_defaults()
    {
    /Enable dragging & dropping of columns within the view/
    setDragDropMode( QAbstractItemView::InternalMove );
    setMovable( true );
    setDragEnabled( true );
    setDropIndicatorShown( true );
    }
    @

    Dragging & Dropping works fine. I can drag headers around, and the sectionMoved( int, int, int ) signal is emitted. My QTableView picks this up so it always knows what index is in what order. As such, my QSortFilterProxy model also always knows the correct order. I save these properly to QSettings, so future instances are started in the same order.

    However, things go pear-shaped when I want to hide a column, and filterAcceptsColumn() returns false. I'm doing something to map each column to the correct column in the parent model. However, it seems something fishy happens to the indexes once once of them is not accepted. A simple example would be a 3-column table view. When the application first starts, the columns would be displayed as indexes 0, 1, and 2. If the user drags and drops 0 from the far left to the far right, they'd be displayed as 1, 2, and 0. headerData(), and data() work fine at this point. However, if I want to hide column 0 via filterAcceptsColumn() returning false, then the view will reference the columns as indexes 0, and 1. I then have to do all types of dancing around to figure out which index is actually the refused one. Not ideal when there are some columns hidden, and some out of order, in no predictable pattern.

    That got a little wordy, and I think I'm missing a fundamental component of having my my view & headerview (hopefully automatically) tell the proxy that the indexes have moved. For what it's worth, I have connected QSortFilterProxyModel::columnsAboutToBeMoved() to a slot to debug, and it is seemingly never called. I've read the Drag & Dropping with Model/View doc, but it seems to mainly cover Mime encoding.

    Any help is appreciated.

    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