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. QTreeView not showing headers after overriding

QTreeView not showing headers after overriding

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 375 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.
  • Match0umM Offline
    Match0umM Offline
    Match0um
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      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);
      }
      
      
      1 Reply Last reply
      3
      • Match0umM Offline
        Match0umM Offline
        Match0um
        wrote on last edited by
        #3

        @mrjj said in QTreeView not showing headers after overriding:

        QTreeView::mouseMoveEvent(event);

        Thank you, it works now 😊 !

        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