How to prohibited drap and drop in a certain column of QHeaderView?
-
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()" ......
-
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()" ......
@qazaq408
Agreed about non-existentsectionMovable(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.
-
-