Results 1 to 3 of 3

Thread: Disable QTreeView item

  1. #1
    Join Date
    Nov 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Disable QTreeView item

    I created a QTreeView and then select an item of the view to create a second view that contains a subset of the original tree showing only the ancesters and offsprings of the selected item using QSortFilterProxyModel.

    In the second view (NOT in the original view), I want to make the ancestors of the selected item un-selectable (grayed out). Is that possible?
    Thanks in advance.

  2. #2
    Join Date
    Oct 2009
    Location
    Hamburg - Germany
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable QTreeView item

    Hi,

    use signal QTreeView::currentChanged and set current index as new QTreeView::setRootIndex of your second tree view. This shows you only the child's of your select item, or use QTreeView::setRootIndex(your_current_index.parent( )) for showing also the selected item.

    Making the items in your second view un-selectable, you must change Qt::ItemFlags of your item .... make a ProxyModel for your treemodel, return all flags only Qt::ItemIsEnabled, map your index from first treeview with mapFromSource() as new rootItem for your second view with the proxy.

  3. #3
    Join Date
    Jan 2011
    Location
    Gordion
    Posts
    52
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disable QTreeView item

    Hi... I need a solution about this...

    I'm making an app with Qt SDK 2010.05... I have a treeview widget. I just want to get current item index of selected item and save it to the registry.
    After that i want to read current index from registry and select item as default

    Qt Code:
    1. QString ipnum = ui->treeView->model()->index(ui->treeView->currentIndex().row(),2).data().toString();
    2. int rowNum = ui->treeView->selectionModel()->currentIndex().row();
    3. ........................................
    4. QSettings writedata("Encom", "Tron");
    5. writedata.beginGroup("CLU");
    6. writedata.setValue("interface_currentIndex",rowNum);
    7. writedata.setValue("interface_ipnum",ipnum);
    8. writedata.endGroup();
    9.  
    10. ........................................
    11.  
    12. //I cant find that how can i set the saved row number, as default row after...
    13. //im try to use the qmodelindex but i cant do it...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. QModelIndex index = (0,0,QModelIndex());
    2. ui->treeView->selectionModel()->setCurrentIndex(index,QItemSelectionModel::Select);
    To copy to clipboard, switch view to plain text mode 

    its not working too.. i cant understand it...
    Last edited by kosasker; 1st February 2011 at 09:27.

Similar Threads

  1. How to disable drag&drop: QTreeView?
    By mirluk in forum Newbie
    Replies: 1
    Last Post: 24th March 2011, 17:09
  2. Disable menu item based to current control selected
    By Suppaman in forum Qt Programming
    Replies: 5
    Last Post: 9th December 2010, 07:33
  3. QTreeView and item editing
    By roxton in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 18:56
  4. QComboBox item disable?
    By Equilibrium in forum Qt Programming
    Replies: 8
    Last Post: 28th November 2007, 17:41
  5. QTreeView | disable multiline,wrapping
    By fleabite in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2007, 11:05

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.