Results 1 to 4 of 4

Thread: highlight a selected row in a QTreeView without clicking on it

  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default highlight a selected row in a QTreeView without clicking on it

    Hi to all,
    I'm using a QTreeView to list items, I hide the QTreeView after a row selection and then show it setting correctly the current index but I don't know how to highlight the row. The following it has been my attempt (rows 18-19):

    Qt Code:
    1. void frmTitoli::funModifica()
    2. {
    3. QModelIndexList selection = ui.tvView->selectionModel()->selectedRows(0);
    4.  
    5. if (!selection.empty())
    6. {
    7. QModelIndex idIndex = selection.at(0);
    8. int id = idIndex.data().toInt();
    9.  
    10. ui.tvView->hide();
    11.  
    12. ...
    13.  
    14. ui.tvView->show();
    15.  
    16. refreshView();
    17.  
    18. ui.tvView->setFocus();
    19. ui.tvView->selectionModel()->setCurrentIndex(idIndex, QItemSelectionModel::SelectCurrent);
    20. }
    21. else
    22. {
    23. QMessageBox::warning(this, tr("Attenzione!"),
    24. tr("Selezionare prima un elemento nella lista!"),
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 

    Thanks!!!

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: highlight a selected row in a QTreeView without clicking on it

    Have you seen QItemSelectionModel::select()?

    You can access the selection model with QAbstractItemView::selectionModel()

  3. #3
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: highlight a selected row in a QTreeView without clicking on it

    Yes, I've tried:

    Qt Code:
    1. void frmTitoli::funModifica()
    2. {
    3. QModelIndexList selection = ui.tvView->selectionModel()->selectedRows(0);
    4. QItemSelection rowSel = ui.tvView->selectionModel()->selection();
    5.  
    6. if (!selection.empty())
    7. {
    8. QModelIndex idIndex = selection.at(0);
    9. int id = idIndex.data().toInt();
    10.  
    11. ui.tvView->hide();
    12.  
    13. ...
    14.  
    15. ui.tvView->show();
    16.  
    17. refreshView();
    18.  
    19. ui.tvView->setFocus();
    20. ui.tvView->selectionModel()->setCurrentIndex(idIndex, QItemSelectionModel::SelectCurrent);
    21. ui.tvView->selectionModel()->select(rowSel, QItemSelectionModel::SelectCurrent);
    22. }
    23. else
    24. {
    25. QMessageBox::warning(this, tr("Attenzione!"),
    26. tr("Selezionare prima un elemento nella lista!"),
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    but it doesn't work

  4. #4
    Join Date
    May 2009
    Location
    Memphis, TN
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: highlight a selected row in a QTreeView without clicking on it

    Did you ever get this working?

    How did you do it?

    Thanks.

Similar Threads

  1. How to tell which row is selected in a QtreeView
    By Valheru in forum Qt Programming
    Replies: 2
    Last Post: 9th November 2007, 22:10
  2. QTreeView: selection behavior upon selected item removal
    By Pieter from Belgium in forum Qt Programming
    Replies: 6
    Last Post: 11th July 2007, 16:00
  3. Replies: 1
    Last Post: 15th March 2007, 20:45
  4. Removing the selected row in a QTreeView
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2006, 11:21
  5. Programattically Clicking an Item in QTreeView
    By johnny_sparx in forum Qt Programming
    Replies: 4
    Last Post: 11th May 2006, 16:26

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.