Hi I am in the process of trying to impliment subclass of the qt library supplied QStandardItemModel and QStandardItem to display items in a Qtreeview. Everything seems to work fine except for when I try to retrieve the selected object from the tree view and use it as a parent object to add children too. The issue is that the selected object retrieves as the inherited type "QStandardItem" and not my subtype "FolderItem":
FolderItem KSLgui::GetSelectedFolder()
{
QItemSelectionModel * model = ui.folderView->selectionModel();
QModelIndexList indexes = model->selectedIndexes();
return (FolderItem)folderModel.itemFromIndex(indexes.first());
}
I get an error telling me that no sutible constructor exists to convert from the two types. I have overloaded all the constructors for both types when making my subtypes and tried to make a new constructor that excepts QStandardItem as a parameter which appears to fix the error but doesn't function properly as it only returns an empty object and not the selected object:
FolderItem::FolderItem()
: QStandardItem()
{
}
FolderItem::FolderItem(const std::string & text)
: QStandardItem(QString::fromStdString(text))
{
}
FolderItem::FolderItem(const QIcon & icon, const QString & text)
: QStandardItem(icon, text)
{
}
FolderItem::FolderItem( int rows, int columns)
: QStandardItem(rows, columns)
{
}
/* returns empty
FolderItem::FolderItem(QStandardItem * stanitem)
{
} */
FolderItem::~FolderItem()
{
}
开发者_如何学运维int FolderItem::type() const
{
return 1001;
}
FolderStructureModel::FolderStructureModel(QObject *parent)
: QStandardItemModel(parent)
{
}
I have included what I beleive to be the significant code.
精彩评论