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 prohibited drap and drop in a certain column of QHeaderView?

How to prohibited drap and drop in a certain column of QHeaderView?

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

    In default, every columns of QHeaderView can drag and drop, and i can;t swap the column by this. Now there is a QTableView, i need to the first column and the second column can't drag and drop, and other columns can drapg and drop as normal;

    i ask AI,AI tell me:

    class MyHeaderView : public QHeaderView{
    //....
    virtual bool sectionMovable(int logicalIndex) const override{
        if(logicalIndex == 0 || logicalIndex == 1)
            return fasle;
        return true;
    }
    //..
    };
    

    But i search the QAssistant, there isn't a function called "sectionMovable()" ......

    JonBJ 1 Reply Last reply
    0
    • qazaq408Q qazaq408

      In default, every columns of QHeaderView can drag and drop, and i can;t swap the column by this. Now there is a QTableView, i need to the first column and the second column can't drag and drop, and other columns can drapg and drop as normal;

      i ask AI,AI tell me:

      class MyHeaderView : public QHeaderView{
      //....
      virtual bool sectionMovable(int logicalIndex) const override{
          if(logicalIndex == 0 || logicalIndex == 1)
              return fasle;
          return true;
      }
      //..
      };
      

      But i search the QAssistant, there isn't a function called "sectionMovable()" ......

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

      @qazaq408
      Agreed about non-existent sectionMovable(int logicalIndex): it does not seem to exist, or if it does (and I do not see it in sources) it's undocumented. So much for AIs/Assistants....

      So far as I can see two possibilities:

      • Connect to signal void QHeaderView::sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex). If one of the first two sections was moved elsewhere then call moveSection() to move it back. Of course this means the user will be able to drag and then see it "pop back" to where it was, which you may or may not consider acceptable.

      • Read through https://stackoverflow.com/questions/76195068/implementing-qtableview-sections-move-properly. Adapt the use of eventFilter() there to recognise the mouse down which starts a section move and reject it if trying to move first/second section.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Did you check the frozen column example ?

        I think it might provide what you are looking for.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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