Hello;
I'm writing Qt widget application. I'm having a QTreeView located on a QTabWidget, this QTabWidget itself located on my QMainWindow.
This following code does not give me the correct selected index when called from QMainWindow method:
QModelIndex CurrentIndex = ui->MyTreeView->currentIndex();
Which one of the four followings approach should I use:
1)
QModelIndexList indexes = ui->MyTreeView->selectionModel()->selection().indexes();
// then capture the particular index in a loop
2)
QModelIndex currentIndex = ui->MTreeView->selectionModel()->currentIndex();
3)
QModelIndex CurrentIndex = ui->MreeView->currentIndex();
4)
void Parent::slot_MyTreeView_selectionChanged()
{
m_SelectedIndex= ui->MyTreeView->currentIndex();
}
Which one is the best?
Is my problem a focus problem?
Should I capture QTreeView selected index only when the QTreeView is visible and my mouse is on it (I'm asking this because sometimes the problematic code works fine)?
Bookmarks