Just to close this off I found a reasonable solution.
Calling setCurrentIndex() expands to the selected node.
Calling setExpanded() expands the selected node too.
{
public:
void readSettings(QSettings& oSettings)
{
QString sLastSelection
= oSettings.
value("LastSelection").
toString();
if (!sLastSelection.isEmpty()) {
setCurrentIndex(index);
setExpanded(index, true);
}
}
void writeSettings(QSettings& oSettings) {
oSettings.setValue("LastSelection", m_oModel.filePath(currentIndex()));
}
protected:
QDirModel& m_oModel;
};
class DirectoryTree : public QTreeView
{
public:
void readSettings(QSettings& oSettings)
{
QString sLastSelection = oSettings.value("LastSelection").toString();
if (!sLastSelection.isEmpty()) {
QModelIndex index = m_oModel.index(sLastSelection);
setCurrentIndex(index);
setExpanded(index, true);
}
}
void writeSettings(QSettings& oSettings) {
oSettings.setValue("LastSelection", m_oModel.filePath(currentIndex()));
}
protected:
QDirModel& m_oModel;
};
To copy to clipboard, switch view to plain text mode
cheers
Dave
Bookmarks