Results 1 to 2 of 2

Thread: the question about define my own selection behavior

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: the question about define my own selection behavior

    You don't need to modify the selection model. You can tell the view which items can be selected by using the Qt::ItemIsSelectable flag in your data model.

    Inherit your model and overwrite QAbstractItemModel::flags:

    Qt Code:
    1. Qt::ItemFlags MyModel::flags(const QModelIndex& index) const
    2. {
    3. if (/* user is allowd to select index.row() */)
    4. return QAbstractTableModel::flags(index) | Qt::ItemIsSelectable;
    5. else
    6. return QAbstractTableModel::flags(index) & ~Qt::ItemIsSelectable;
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to shentian for this useful post:

    calmspeaker (22nd June 2009)

Similar Threads

  1. Pre app.exec() behavior question
    By sgmurphy19 in forum Qt Programming
    Replies: 3
    Last Post: 15th September 2008, 22:02
  2. odd double widgets
    By jhearon in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2008, 18:18
  3. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 16:00
  4. QListWidget selection behavior as in Windows XP
    By Levon Nikoghosyan in forum Qt Programming
    Replies: 1
    Last Post: 9th January 2007, 13:11
  5. QListWidget selection behavior
    By Arthur in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2006, 14:10

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
  •  
Qt is a trademark of The Qt Company.