Results 1 to 2 of 2

Thread: How to disable drag&drop: QTreeView?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default How to disable drag&drop: QTreeView?

    Simple application:

    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QStandardItemModel model(0, 4);
    8. model.setHeaderData(0,Qt::Horizontal,QObject::tr("No."));
    9. model.setHeaderData(1,Qt::Horizontal,QObject::tr("Message"));
    10. model.setHeaderData(2,Qt::Horizontal,QObject::tr("Begin"));
    11. model.setHeaderData(3,Qt::Horizontal,QObject::tr("End"));
    12.  
    13. model.setItem(0, 0, new QStandardItem("1"));
    14. model.setItem(0, 1, new QStandardItem("Error 1"));
    15. model.setItem(0, 2, new QStandardItem("09-12-2010, 14:00"));
    16. model.setItem(0, 3, new QStandardItem("09-12-2010, 14:25"));
    17. model.setItem(1, 0, new QStandardItem("2"));
    18. model.setItem(1, 1, new QStandardItem("Error 2"));
    19. model.setItem(1, 2, new QStandardItem("09-12-2010, 12:00"));
    20. model.setItem(1, 3, new QStandardItem("09-12-2010, 14:25"));
    21.  
    22. QTreeView tree;
    23. tree.setModel(&model);
    24. tree.setColumnWidth(0,30);
    25. tree.setColumnWidth(1,410);
    26. tree.setColumnWidth(2,105);
    27. tree.setColumnWidth(3,85);
    28. tree.setRootIsDecorated(false);
    29. tree.setAlternatingRowColors(true);
    30. tree.setSortingEnabled(true);
    31. tree.sortByColumn(2, Qt::DescendingOrder);
    32. tree.show();
    33.  
    34. return app.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    I can't disable DnD for headers. I tried: setDragEnabled(false), setDragDropMode(QAbstractItemView::NoDragDrop) but to no avail. Could you comment?

  2. #2
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: How to disable drag&drop: QTreeView?

    You could use tree.header()->setMovable(false) to disable column "dragging".

Similar Threads

  1. QTreeView: Drag and Drop
    By laugusti in forum Newbie
    Replies: 7
    Last Post: 19th March 2010, 20:05
  2. Drag&Drop problem in a QTreeView
    By Andy_CH in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 23:45
  3. Drag and drop in QTreeView
    By Valheru in forum Qt Programming
    Replies: 3
    Last Post: 27th July 2008, 10:36
  4. drag and drop from QTreeView
    By Untersander in forum Qt Programming
    Replies: 1
    Last Post: 10th April 2006, 10:00
  5. Drag & drop for QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 2
    Last Post: 30th January 2006, 15:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.