Results 1 to 6 of 6

Thread: Make Only some columns of QTreeView read only

  1. #1
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Make Only some columns of QTreeView read only

    Hi,
    I have a QTreeView having 10 rows and each row has 5 columns.
    Now i want to make first 4 columns of each row readonly. Only the last column can be edited by the user.
    How to do this. Pls help.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Make Only some columns of QTreeView read only

    Reimplement flags() on the model, set the Qt::ItemIsEditable on items you want editable and clear the flag on others.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Make Only some columns of QTreeView read only

    i have done this but now the row highlight color is gone.
    i have MoveRowUp and MoveRowDone functions when am doing that row is not highlighted.
    Only the last column which is editable is highlited

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Make Only some columns of QTreeView read only

    You are returning wrong flags. You should return default flags + optionally ItemIsEditable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2014
    Posts
    15
    Thanks
    1
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Make Only some columns of QTreeView read only

    Thanks for ur reply wysota.
    Actually am new to Qt so am not getting how to reimplement flags and make certain item editable and clearing flags.
    Can u please elaborate through some sample code.
    Thanks again.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Make Only some columns of QTreeView read only

    Quote Originally Posted by GAURAV PANT View Post
    Actually am new to Qt so am not getting how to reimplement flags and make certain item editable and clearing flags.
    This is plain C++. You inherit, reimplement the flags() method and use the bit logical operations to assemble a set of bits you want active and return the from the method. You can use the base class implementation to fetch the default flags.

    Qt Code:
    1. Qt::ItemFlags MyModel::flags(const QModelIndex &index) const {
    2. return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; // enable ItemIsEditable for all items
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTreeView and spanning columns
    By Lykurg in forum Qt Programming
    Replies: 4
    Last Post: 22nd September 2017, 11:58
  2. Replies: 0
    Last Post: 26th June 2012, 04:07
  3. QTreeview Columns lengths
    By kiran p in forum Qt Programming
    Replies: 0
    Last Post: 18th April 2011, 13:12
  4. Moving columns/hiding columns in QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 4
    Last Post: 14th March 2007, 16:22
  5. [qt4 & Xp] resize columns of a QTreeView
    By incapacitant in forum Newbie
    Replies: 4
    Last Post: 2nd March 2006, 14:06

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.