我已經樹視圖中,我想通過file_dialog.getOpenFileNames()顯示用戶選擇的文件; file_dialog是QFileDialog。 我沒有創建模型類:模型視圖困難
class File_Display_Model : public QAbstractItemModel
{
Q_OBJECT
private:
QStringList* selected_files_;
public:
explicit File_Display_Model(QObject *parent = nullptr,QStringList* selected_files = nullptr);
int File_Display_Model::columnCount(const QModelIndex & parent) const
{
selected_files_->count();
}
QVariant File_Display_Model::data(const QModelIndex & index, int role) const
{
if (!index.isValid())
{
return QVariant();
}
else
{
if (role == Qt::DisplayRole) {
if (index.row() == index.column())
{
return 0;
}
else
{
return selected_files_->at(role);
}
}
return QVariant();
}
}
QModelIndex File_Display_Model::index(int row, int column, const QModelIndex & parent) const
{
/*DUMMY - HERE I JUST DON'T KNOW WHAT TO RETURN*/
return QModelIndex();
}
QModelIndex File_Display_Model::parent(const QModelIndex & index) const
{
return QModelIndex();
}
int File_Display_Model::rowCount(const QModelIndex & parent) const
{
selected_files_->count();
}
signals:
public slots:
};
而且我還提供了這個類的模型樹視圖。這個類中的索引方法存在問題 - 我不知道要返回什麼。
有人可以幫助我,並指導我如何使其工作,以便用戶選擇的文件顯示在樹視圖中?
[請勿濫用'code formatting'](https://meta.stackexchange.com/q/135112/349538) –