Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

drag and drop non-frozen column header to frozen column header



  • I have first three columns frozen and rest columns non frozen. non frozen columns could be swapped and fixed are not allowed to be swapped. there is a problem with third column which is frozen. if the fourth column is dropped into 3rd column, 3rd column is duplicated which shouldnt happen . How to avoid duplicating. non frozen columns swapping works fine


  • Lifetime Qt Champion

    Hi and welcome to the forums
    so how did you make the frozen ones ?
    like this ?
    https://doc.qt.io/qt-5/qtwidgets-itemviews-frozencolumn-example.html
    So you have a secondary view ?



  • Yes its this way


  • Lifetime Qt Champion

    Hi
    but how did you make the drag and drop considering this example does not implement it.
    I think you might be using default drag and drop which as my make a copy.

    did you try adjusting the default drop action to Move Action ?

    alt text



  • There are two parts in this. Say for eg first 3 columns are frozen. these are fixed. Remaining columns say for eg 4 columns(num of non frozen columns varies on every run) are non frozen. These 4 columns can be swapped. I also have horizontal scroll bar for non frozen columns. first 3 columns cannot be dragged. But if the header(QHeaderView) of the 4 col is dropped to 3rd(happens with 3rd column only) then 4th col has col3+col4(duplicated).. How to avoid duplicating.
    Col1 Col2 Col3 Col3+col4 Col5

    When col4 is dropped into col3, it should remain as it is. nothing should change.
    I cannot use header->setSectionsMovable(false); as this would make my movable columns fixed.


  • Lifetime Qt Champion

    Hi

    But what happens when you drop 4 to 3 ?
    It then added all items from one col to the existing col?
    Like a selection ?
    Do you use default drag and drop or did you implement your own ?



  • On dropping 4 to 3 , col 4 changes to col 4 +col3. col 3 and rest of the columns remains unchanged. for drag/drop header is used. its default drag/drop. the problem is only with col 3 and 4. Rest are fine



  • But on dropping 4 to 3 2nd time evrything is becomes fine.
    col1 col2 col3 col4 col5.....
    I have few connect signals for expanding, collapsing, header click etc.


  • Lifetime Qt Champion

    @Shines
    HI
    Sorry, it's impossible to guess without a minimal example that reproduces this behavior.

    I tried to change the frozen example to allow header re-arranging but i could not make it
    do a drag and drop that way where it would copy new items to the existing column.

    • But on dropping 4 to 3 2nd time evrything is becomes fine

    so second time you do it, all the duplicated are removed and all is good?

    I wonder if its just a update bug then.



  • yes on first drop col4 is col4 +col3. on 2nd drop duplicates are removed


  • Lifetime Qt Champion

    @Shines

    Ok. that is pretty odd. If the items was indeed added to the column, i doubt anything would just remove them again.

    You must use the debugger to find out what is going on.


Log in to reply