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 drag columns to move them

QTableView drag columns to move them

Scheduled Pinned Locked Moved Solved General and Desktop
qtableview
5 Posts 2 Posters 5.3k Views 3 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.
  • M Offline
    M Offline
    mjsurette
    wrote on last edited by
    #1

    I'm using Qt 5.7 and am trying to move columns around by dragging them. Googling this I find that setSectionsMovable(true); should do the trick, but it doesn't.

    In my setup I have the following

        ui->tvRMA->setModel(&_displayModel);
        ui->tvRMA->setSortingEnabled(false);
        ui->tvRMA->setSelectionBehavior(QAbstractItemView::SelectRows);
        ui->tvRMA->horizontalHeader()->setSectionsMovable(true);
    

    This does everything that I want except allow me to drag columns around. What more needs to be done?

    Mike

    1 Reply Last reply
    0
    • jerome_isAviableJ Offline
      jerome_isAviableJ Offline
      jerome_isAviable
      wrote on last edited by
      #2

      Hi mjsurette,
      I think, because it is a view linked with a model, you have to implement some current model function with that be possible. You setting the view, you may have also to setting the model now.

      old thred on qtcentre.org:
      texte du lien
      texte du lien

      hope this will help you, tell us/share your solution when fixed.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mjsurette
        wrote on last edited by
        #3

        Thank you @jerome_isAviable for your reply. I did check out your links, but sadly they were of no help.

        Changing the model in order to change the view breaks the whole model-view concept of separating the data from the display. Changing the model would change all views, not just the current one. Having movable columns should be on a per view basis for what I want.

        Your first link involves changing the model as you suggest, which is not what I need.

        The second link suggests calling setColumnMovingEnabled() which is the Qt3 equivalent of setSectionsMovable() if I'm reading this right.

        Any other thoughts?

        I will post the solution if/when I find it.

        Mike

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mjsurette
          wrote on last edited by
          #4

          Well, it now works. The problem is I don't know how. I started working on another feature and when I came back to this it was working. There is no call to setSectionsMovable(). I did a grep on 'mov' and only two results, neither of which have anything to do with this.

          For now, this is a mystery.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mjsurette
            wrote on last edited by
            #5

            After much experimentation and some luck I found the solution to this mystery.

            On startup I had

            ui->tvRMA->horizontalHeader()->restoreState(...);
            

            which restored invalid information from previous sessions with different layouts. Clearing the database of previous sessions brought back the proper behaviour.

            Mike

            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