Unsolved qcolumnview, how to determine whether it is a file
-
Hello, everyone
I has a problem when the qcolumnview was used to show the file system tree.
first, I set the rootpath
void MainWindow::on_actionOpen_Image_triggered() { FileImgDir = QFileDialog::getExistingDirectory(this,tr("Select a directory including Images(*.jpg,*.tif,*,png,*.txt,*.bmp)"),"/home",QFileDialog::ShowDirsOnly|QFileDialog::DontResolveSymlinks); QStringList filters; filters << "*.jpg"<<"*.JPG"<<"*.tif"<<"*.TIF"<<"*.tiff"<<"*.TIFF"<<"*.png"<<"*.PNG"<<"*.txt"<<"*.TXT"<<"*.bmp"<<"*.BMP"; imgmodel->setNameFilters(filters); //imgmodel is an object of the filesystemmodel ui->Image_filenames_columnview->setModel(imgmodel); ui->Image_filenames_columnview->setRootIndex(imgmodel->setRootPath(FileImgDir)); }
define the slot function for the signal click.
void MainWindow::on_Image_filenames_columnview_clicked(const QModelIndex &index) { Path_Img_Name=imgmodel->fileInfo(index).absolutePath() + "/" + index.data().toString(); filename = Path_Img_Name.toStdString(); }
it is working for the file name, but do not for directory name.
I know it would not work on the directory name, the file name and directory name are differrent represented in the qmodelindex. But I do not know how to handle them.default action of the signal click for directory is to open it in the next column, but do not work, how implement it again in the slot function?