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

QTreeView not showing headers after overriding



  • Hi guys, I am facing the following issue :

    I wanted to disable dragging on my QTreeView. For that, I have created a custom TreeView overriding mousemoveEvent that works well :

    TreeView::TreeView(QWidget *parent)
        :QTreeView(parent)
    {
        
    }
    
    void TreeView::mouseMoveEvent(QMouseEvent *event){
        if(state() == DraggingState || state() == DragSelectingState || state() == ExpandingState){
            return;
        }
    }
    

    But after doing that, my TreeView is not showing the header anymore. The header was only shown using QTreeView. What did I miss ?


  • Lifetime Qt Champion

    Hi
    Whats wrong with setAcceptDrops(false); ?
    or
    setDragDropMode(QAbstractItemView::NoDragDrop);
    (if its to prevent internal reordering)

    Well one thing that could be messing with the headers is that you
    dont call QTreeView::mouseMoveEvent(event);
    To let base class do what it normally does so that might break things.

    void TreeView::mouseMoveEvent(QMouseEvent *event){
        if(state() == DraggingState || state() == DragSelectingState || state() == ExpandingState){
            return;
        }
    QTreeView::mouseMoveEvent(event);
    }
    
    


  • @mrjj said in QTreeView not showing headers after overriding:

    QTreeView::mouseMoveEvent(event);

    Thank you, it works now 😊 !


Log in to reply