Results 1 to 6 of 6

Thread: QTreeView rows editable

  1. #1
    Join Date
    Sep 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTreeView rows editable

    Hello,

    How can I disable the editable rows in QTreeView, I'm using the standard model "QStandardItemModel"



    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeView rows editable

    Use QStandardItem::setFlags() to remove Qt::ItemIsEditable which is turned on by default:
    Qt Code:
    1. item->setFlags(item->flags() & ~Qt::ItemIsEditable);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView rows editable

    Qt Code:
    1. QAbstractItemModel *pModel = new QStandardItemModel(parent);
    To copy to clipboard, switch view to plain text mode 
    I got this error: error C2039: 'setFlags' : is not a member of 'QAbstractItemModel'
    How I'm supoused to use QStandardItem with QAbstractItemModel?

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeView rows editable

    So, you're not using QStandardItems to fill QStandardItemModel? Alternative approach is to reimplement QAbstractItemModel::flags() and make sure no Qt::ItemIsEditable is returned:
    Qt Code:
    1. Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex& index) const
    2. {
    3. return (QStandardItemModel::flags(index) & ~Qt::ItemIsEditable);
    4. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  5. #5
    Join Date
    Sep 2007
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView rows editable

    Thank you
    My second question is: how to remove the dotted border in the selected row on the selected column like the picture below:


  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QTreeView rows editable

    J-P Nurmi

Similar Threads

  1. Replies: 4
    Last Post: 26th September 2011, 12:02
  2. Model/View Confusion in QTreeView - number of rows
    By themolecule in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 22:45
  3. QTableView - Restrict editable rows.
    By jimroos in forum Newbie
    Replies: 2
    Last Post: 4th June 2007, 07:31
  4. [QT4] QTreeView and rows with multiple lines
    By KShots in forum Qt Programming
    Replies: 8
    Last Post: 30th March 2006, 18:47
  5. [Qt 4.x] Highliting rows in a QTreeView
    By Moppel in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2006, 10:00

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.