FolderChooser::FolderChooser(const QString & start_folder,QWidget *parent) : QDialog(parent), ui(new Ui::FolderChooser) { ui->setupUi(this); QFileSystemModel *model = new QFileSystemModel(ui->folderView); model->setFilter(QDir::Dirs|QDir::Drives|QDir::NoDotAndDotDot); ui->folderView->setModel(model); QModelIndex root_index = model->setRootPath(start_folder); if (root_index.isValid()) { QItemSelection selection(root_index,model->index(root_index.row(),model->columnCount()-1,root_index.parent())); ui->folderView->selectionModel()->select(selection,QItemSelectionModel::ClearAndSelect); ui->folderView->scrollTo(root_index); ui->folderView->expand(root_index); } connect(ui->folderView->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(selectionChanged())); #if QT_VERSION >= 0x050000 ui->folderView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); #else ui->folderView->header()->setResizeMode(0, QHeaderView::ResizeToContents); #endif ui->folderView->header()->hideSection(1); ui->folderView->header()->hideSection(2); ui->folderView->header()->hideSection(3); selectionChanged(); }
//! [0] //! [1] int main(int argc, char *argv[]) { QApplication app(argc, argv); QSplitter *splitter = new QSplitter; //! [2] //! [3] QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir::currentPath()); //! [0] //! [2] //! [4] //! [5] QTreeView *tree = new QTreeView(splitter); //! [3] //! [6] tree->setModel(model); //! [4] //! [6] //! [7] tree->setRootIndex(model->index(QDir::currentPath())); //! [7] QListView *list = new QListView(splitter); list->setModel(model); list->setRootIndex(model->index(QDir::currentPath())); //! [5] QItemSelectionModel *selection = new QItemSelectionModel(model); tree->setSelectionModel(selection); list->setSelectionModel(selection); //! [8] splitter->setWindowTitle("Two views onto the same file system model"); splitter->show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QFileSystemModel model; QWidget window; QTreeView *tree = new QTreeView(&window); tree->setMaximumSize(1000, 600); QHBoxLayout *layout = new QHBoxLayout; layout->setSizeConstraint(QLayout::SetFixedSize); layout->addWidget(tree); window.setLayout(layout); model.setRootPath(""); tree->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); tree->setModel(&model); tree->setAnimated(false); tree->setIndentation(20); tree->setSortingEnabled(true); tree->header()->setStretchLastSection(false); window.setWindowTitle(QObject::tr("Dir View")); tree->header()->setSectionResizeMode(QHeaderView::ResizeToContents); window.show(); return app.exec(); }
void MainWindow::createDockWindows() { /* Add HOL widget */ QDockWidget *dock = new QDockWidget(tr("HOL Process"), this); dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); mHOLWidget = new HOLWidget; dock->setWidget(mHOLWidget); addDockWidget(Qt::RightDockWidgetArea, dock); /* File System View */ QDockWidget *fileDock = new QDockWidget(tr("Project"), this); fileDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); mFileViewSplitter = new QSplitter; QFileSystemModel *fileSystemModel = new QFileSystemModel; fileSystemModel->setRootPath(QDir::currentPath()); QItemSelectionModel *itemSelectionModel = new QItemSelectionModel(fileSystemModel); connect(itemSelectionModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(fileViewItemSelected(QModelIndex,QModelIndex))); QTreeView* tree = new QTreeView(mFileViewSplitter); tree->setModel(fileSystemModel); tree->setRootIndex(fileSystemModel->index(QDir::currentPath())); tree->setSelectionModel(itemSelectionModel); tree->hideColumn(2); tree->hideColumn(3); tree->hideColumn(1); fileDock->setWidget(mFileViewSplitter); addDockWidget(Qt::RightDockWidgetArea, fileDock); }
LaunchPage::LaunchPage(QWidget *parent) : QWidget(parent), ui(new Ui::LaunchPage), m_argsModel(new QStringListModel(this)) { ui->setupUi(this); connect(ui->progSelectButton, SIGNAL(clicked()), SLOT(showFileDialog())); connect(ui->addArgButton, SIGNAL(clicked()), SLOT(addArgument())); connect(ui->removeArgButton, SIGNAL(clicked()), SLOT(removeArgument())); connect(ui->progEdit, SIGNAL(textChanged(QString)), SIGNAL(updateButtonState())); ui->argsBox->setModel(m_argsModel); QCompleter *pathCompleter = new QCompleter(this); QFileSystemModel *fsModel = new QFileSystemModel(this); fsModel->setRootPath(QDir::rootPath()); pathCompleter->setModel(fsModel); ui->progEdit->setCompleter(pathCompleter); QSettings settings; ui->progEdit->setText(settings.value(QLatin1String("Launcher/Program")).toString()); m_argsModel->setStringList(settings.value(QLatin1String("Launcher/Arguments")).toStringList()); ui->accessMode->setCurrentIndex(settings.value(QLatin1String("Launcher/AccessMode")).toInt()); updateArgumentButtons(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setupUi(this); Settings *settings = Settings::getInstance(); this->setWindowIcon(QIcon(":/icons/mmmmp.ico")); this->filesystem->header()->setResizeMode(QHeaderView::ResizeToContents); this->setStyleSheet(settings->styleSheet(this)); leftTabs->setStyleSheet(settings->styleSheet(leftTabs)); widgetSearchBar->setStyleSheet(settings->styleSheet(0)); splitter->setStyleSheet(settings->styleSheet(splitter)); volumeSlider->setStyleSheet(settings->styleSheet(volumeSlider)); seekSlider->setStyleSheet(settings->styleSheet(seekSlider)); QFileSystemModel *fileSystemModel = new QFileSystemModel(this); fileSystemModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); QStringList filters; filters << "*.mp3"; fileSystemModel->setNameFilters(filters); filesystem->setModel(fileSystemModel); filesystem->setRootIndex(fileSystemModel->setRootPath(QDesktopServices::storageLocation(QDesktopServices::MusicLocation))); // Hide columns "size" and "date modified" columns, useless for almost everyone filesystem->setColumnHidden(1, true); filesystem->setColumnHidden(3, true); // Special behaviour for media buttons mediaButtons << skipBackwardButton << seekBackwardButton << playButton << pauseButton << stopButton << seekForwardButton << skipForwardButton << repeatButton << shuffleButton; foreach (MediaButton *b, mediaButtons) { b->setStyleSheet(settings->styleSheet(b)); }
void MainWindow::on_path_returnPressed() { QFileSystemModel *FSM; QStringList sImageFilters; QDir d; QString sPath; sImageFilters << "*.png"; //Show files in the tree view sPath = ui->path->text(); FSM = new QFileSystemModel(this); FSM->setFilter(QDir::NoDotAndDotDot | QDir::AllEntries); FSM->setRootPath(sPath); FSM->setNameFilters(sImageFilters); ui->file_browser->setModel(FSM); ui->file_browser->setRootIndex(FSM->index(sPath)); ui->file_browser->hideColumn(1); ui->file_browser->hideColumn(2); ui->file_browser->hideColumn(3); //initiate the filelist to the image d.setPath(ui->path->text()); d.setFilter( QDir::Files | QDir::NoSymLinks ); d.setNameFilters(sImageFilters); filelist = d.entryInfoList(); //initiate the dir for the yml files ymlFileDir = ui->path->text(); ymlFileDir.append("/data/"); }
void fileWorker::listFile(QTreeView *tree, QString path) { QFileSystemModel *model; model = (QFileSystemModel*)tree->model(); model->setRootPath(path); tree->setRootIndex(model->index(path)); }
Q_DECL_EXPORT int main(int argc, char **argv) { qmlRegisterType<QAbstractItemModel>(); qmlRegisterType<QTimer>("net.mkiol.kaktus", 1, 0, "QTimer"); qmlRegisterType < AbstractItemModel > ("com.kdab.components", 1, 0, "AbstractItemModel"); qmlRegisterType < WebImageView > ("org.labsquare", 1, 0, "WebImageView"); qRegisterMetaType < DatabaseManager::CacheItem > ("CacheItem"); Application app(argc, argv); app.setApplicationName(APP_NAME); app.setApplicationVersion(VERSION); Settings* settings = Settings::instance(); /*QTranslator translator; const QString filename = QString::fromLatin1("kaktus_%1").arg( settings->getLocale()=="" ? QLocale().name() : settings->getLocale()); if (translator.load(filename, "app/native/qm")) app.installTranslator(&translator);*/ settings->qml = QmlDocument::create("asset:///main.qml"); settings->qml->documentContext()->setContextProperty("APP_NAME", APP_NAME); settings->qml->documentContext()->setContextProperty("VERSION", VERSION); settings->qml->documentContext()->setContextProperty("AUTHOR", AUTHOR); settings->qml->documentContext()->setContextProperty("PAGE", PAGE); NetworkAccessManagerFactory factory(settings->getDmUserAgent()); settings->qml->defaultDeclarativeEngine()->setNetworkAccessManagerFactory(&factory); DatabaseManager db; settings->db = &db; DownloadManager dm; settings->dm = &dm; CacheServer cache(&db); settings->cache = &cache; Utils utils; bb::device::DisplayInfo display; QFileSystemModel *model = new QFileSystemModel(&app); model->setRootPath("app/"); settings->qml->setContextProperty("db", &db); settings->qml->setContextProperty("utils", &utils); settings->qml->setContextProperty("dm", &dm); settings->qml->setContextProperty("cache", &cache); settings->qml->setContextProperty("settings", settings); settings->qml->setContextProperty("_fileSystemModel", model); settings->qml->setContextProperty("display", &display); QObject::connect(settings->qml->defaultDeclarativeEngine(), SIGNAL(quit()), QCoreApplication::instance(), SLOT(quit())); AbstractPane *root = settings->qml->createRootObject<AbstractPane>(); Application::instance()->setScene(root); return Application::exec(); }
void FilterDialog::setUpCompleter() { QCompleter* completer = new QCompleter(this); QFileSystemModel* fsmodel = new QFileSystemModel(completer); fsmodel->setReadOnly(true); fsmodel->setRootPath(""); completer->setModel(fsmodel); folderPathLineEdit->setCompleter(completer); }
void CMainWindow::OnFolderSelected(QTreeWidgetItem *p_pItem, int) { //ui->folderViewer->SetFolder(p_pItem->data(0, Qt::UserRole).value<CFolder*>()); CFolder *pFolder = p_pItem->data(0, Qt::UserRole).value<CFolder*>(); QString sPath = pFolder->GetDir().absolutePath(); QFileSystemModel *pModel = (QFileSystemModel *)ui->folderViewer->model(); pModel->setRootPath(sPath); ui->folderViewer->setRootIndex(pModel->index(sPath)); }
void FileViewer::setRoot(const QString & dirname) { if (dirname.isNull()) { return; } else { QFileSystemModel* model = static_cast<QFileSystemModel *>(this->model()); setRootIndex(model->index(dirname)); model->setRootPath(dirname); this->header()->resizeSections(QHeaderView::ResizeToContents); } }
void TestQTestComplex::pl_filesystemmodel() { QFileSystemModel *model = new QFileSystemModel(); // Start to read the path (this starts a new thread) model->setRootPath(QDir::currentPath()); QCoreApplication::processEvents(QEventLoop::AllEvents, 100); delete model; }
void MainWindow::on_m_pushButtonOk_clicked() { QFileSystemModel *fsm = new QFileSystemModel(); fsm->setRootPath("D:/Movies"); //fsm->setNameFilters(QString("A*,B*").split(',')); //ui->m_listView->setCurrentIndex(fsm->index("c:/windows")); //ui->m_listView->setModel(fsm); ui->m_treeView->setModel(fsm); }
//! [11] void MainWindow::changeModel() { delete completer; completer = new QCompleter(this); completer->setMaxVisibleItems(maxVisibleSpinBox->value()); switch (modelCombo->currentIndex()) { default: case 0: { // Unsorted QFileSystemModel QFileSystemModel *fsModel = new QFileSystemModel(completer); fsModel->setRootPath(""); completer->setModel(fsModel); contentsLabel->setText(tr("Enter file path")); } break; //! [11] //! [12] case 1: { // FileSystemModel that shows full paths FileSystemModel *fsModel = new FileSystemModel(completer); completer->setModel(fsModel); fsModel->setRootPath(""); contentsLabel->setText(tr("Enter file path")); } break; //! [12] //! [13] case 2: { // Country List completer->setModel(modelFromFile(":/resources/countries.txt")); QTreeView *treeView = new QTreeView; completer->setPopup(treeView); treeView->setRootIsDecorated(false); treeView->header()->hide(); treeView->header()->setStretchLastSection(false); treeView->header()->setResizeMode(0, QHeaderView::Stretch); treeView->header()->setResizeMode(1, QHeaderView::ResizeToContents); contentsLabel->setText(tr("Enter name of your country")); } break; //! [13] //! [14] case 3: { // Word list completer->setModel(modelFromFile(":/resources/wordlist.txt")); completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel); contentsLabel->setText(tr("Enter a word")); } break; } changeMode(modeCombo->currentIndex()); changeCase(caseCombo->currentIndex()); completer->setWrapAround(wrapCheckBox->isChecked()); lineEdit->setCompleter(completer); connect(wrapCheckBox, SIGNAL(clicked(bool)), completer, SLOT(setWrapAround(bool))); }
FlowWidgetListTab::FlowWidgetListTab(QWidget *parent) : QWidget(parent) { DUI::DListView *listView = new DUI::DListView(this); QFileSystemModel *model = new QFileSystemModel(this); ItemDelegate *delegate = new ItemDelegate(listView); listView->setItemDelegate(delegate); listView->setSpacing(10); listView->setResizeMode(QListView::Adjust); listView->setCacheBuffer(50); listView->setModel(model); listView->setOrientation(QListView::LeftToRight, true); model->setRootPath("/"); listView->setRootIndex(model->index("/")); connect(listView, &DUI::DListView::doubleClicked, this, [listView](const QModelIndex &index) { listView->setRootIndex(index); }); QWidget *button_widget = new QWidget; QHBoxLayout *buttonLayout = new QHBoxLayout(button_widget); QPushButton *button_back = new QPushButton("^"); QPushButton *button_switch = new QPushButton("switch view mode"); connect(button_back, &QPushButton::clicked, listView, [listView] { listView->setRootIndex(listView->rootIndex().parent()); }); connect(button_switch, &QPushButton::clicked, button_switch, [listView, delegate] { if(listView->isWrapping()) { listView->setOrientation(QListView::TopToBottom, false); listView->clear(); } else { listView->setOrientation(QListView::LeftToRight, true); } delegate->viewIsWrapping = listView->isWrapping(); }); buttonLayout->addWidget(button_back); buttonLayout->addWidget(button_switch); listView->addFooterWidget(button_widget); QVBoxLayout *main_layout = new QVBoxLayout(this); main_layout->setMargin(0); main_layout->setSpacing(0); main_layout->addWidget(listView); }
void MainWindow::updateListView(){ QFileSystemModel *model = new QFileSystemModel; QString path(QFileInfo(currentFile->fileName()).dir().path()); model->setFilter(QDir::AllDirs | QDir::AllEntries); QStringList flt; flt << "*.md" << "*.mkd"; model->setNameFilters(flt); model->setNameFilterDisables(false); model->setRootPath(path); ui->listView->setModel(model); ui->listView->setRootIndex(model->index(path)); }
void TagEditor::readSettings(){ /* guiSettings->beginGroup("MainWindow"); //this->resize(guiSettings->value("size", QSize(630, 750)).toSize()); //this->move(guiSettings->value("pos", QPoint(200, 200)).toPoint()); guiSettings->endGroup(); */ style = guiSettings->value("style","WindowsXP").toString(); startupFolder = guiSettings->value("startupFolder","").toString(); QString defaultExt = "*.mp3;*.wma;*.wav;*.ogg;*.aac;*.ac3;*.m4a"; extensions = guiSettings->value("extensions",defaultExt.split(";")).toStringList(); QFileSystemModel *model = static_cast<QFileSystemModel*>(TreeView->model()); model->setRootPath(startupFolder); model->setNameFilters(extensions); model->setNameFilterDisables(false); TreeView->setRootIndex(model->index(startupFolder)); treeViewLabel->setText(startupFolder); //api_key = guiSettings->value("api_key","").toString(); showSaveTagWarning = guiSettings->value("showSaveTagWarning",true).toBool(); subfolders = guiSettings->value("subfolders",true).toBool(); ArtistCheckbox->setChecked( guiSettings->value("artistChecked",true).toBool() ); TitleCheckbox->setChecked( guiSettings->value("titleChecked",true).toBool() ); AlbumCheckbox->setChecked( guiSettings->value("albumChecked",true).toBool() ); YearCheckbox->setChecked( guiSettings->value("yearChecked",true).toBool() ); TrackCheckbox->setChecked( guiSettings->value("trackChecked",true).toBool() ); GenreCheckbox->setChecked( guiSettings->value("genreChecked",true).toBool() ); CommentCheckbox->setChecked( guiSettings->value("commentChecked",true).toBool() ); lastStyleSheetFolder = guiSettings->value("lastStyleSheetFolder","").toString(); TreeWidget_->setShowFullFileName( guiSettings->value("showFullFileName",false).toBool() ); TreeWidget_->setShowTagInfo( guiSettings->value("showTagInfo",false).toBool() ); TreeWidget_->setSortingEnabled( guiSettings->value("sortingEnabled",true).toBool() ); if(TreeWidget_->isSortingEnabled()){ TreeWidget_->header()->setSortIndicator( guiSettings->value("sortColumn",0).toInt(), static_cast<Qt::SortOrder>(guiSettings->value("sortOrder",0).toInt()) ); TreeWidget_->header()->setSortIndicatorShown(true); } QVariantList colstmp = guiSettings->value("columns").toList(); QList<Global::TagField> cols; for(int i=0;i<colstmp.size();i++){ qDebug()<<"colstmp[i] "<<colstmp[i]; cols.append(static_cast<Global::TagField>(colstmp[i].toInt())); } TreeWidget_->setColumnsList(cols); restoreState(guiSettings->value("windowState").toByteArray()); restoreGeometry(guiSettings->value("geometry").toByteArray()); //splitter->setSizes(guiSettings->value("splittersizes").value< QList<int> >() ); scriptEditor_->setText(guiSettings->value("script","").toString()); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QFileSystemModel dir; dir.setRootPath("/"); QtTreeModelAdaptor adaptor(&dir); QtTreeWidgetNG widget; widget.controller()->setModel(&adaptor); widget.show(); return app.exec(); }
void RestoreBackup::buildDialog() { m_BackupTreeview = new QTreeView(); QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir::currentPath()); //model->setRootPath("/andrew0/home/andy/Devsrc/Qt/"); m_BackupTreeview->setModel(model); QHBoxLayout *hLayout = new QHBoxLayout(); //hLayout->addChildWidget(m_BackupTreeview); hLayout->addWidget(m_BackupTreeview); setLayout(hLayout); }
receive::receive(QWidget *parent) : QDialog(parent), ui(new Ui::receive) { ui->setupUi(this); this->setWindowTitle("收件箱"); this->setStyleSheet("#receive{border-image: url(:/receiv_background.jpg);}"); count =0; QFileSystemModel filename; ui->treeView->setRootIndex(filename.setRootPath(":/")); ui->treeView->setModel(&filename); }
QWidget* MainWidget::createTreeWidget() { QFileSystemModel *fModel = new QFileSystemModel; fModel->setRootPath(""); fModel->setFilter(QDir::Dirs | QDir::NoDotAndDotDot); tView = new QTreeView; tView->setStyleSheet("QTreeView{border:0;}"); tView->setModel(fModel); tView->setAnimated(false); tView->setHeaderHidden(true); for(int i=1; i<fModel->columnCount(); i++){ tView->setColumnHidden(i, true); } connect(tView,SIGNAL(clicked(QModelIndex)),this,SLOT(slotTreeItemClicked(QModelIndex))); return tView; }
void MainWindow::populate() { QFileSystemModel *model = new QFileSystemModel; model->setRootPath(QDir::homePath()); QModelIndex index = model->index(QDir::homePath()); ui->treeView->setModel(model); ui->treeView->expand(index); ui->treeView->scrollTo(index); ui->treeView->setCurrentIndex(index); ui->treeView->setColumnWidth(0, 128); ui->treeView->hideColumn(1); ui->horizontalSlider->setValue(36); ui->horizontalSlider_2->setValue(36); ui->treeView_2->setModel(model); ui->treeView_2->expand(index); ui->treeView_2->scrollTo(index); ui->treeView_2->setCurrentIndex(index); }
void EditorTab::currentProjectChanged(WebProject* p) { /*must be remove*/ m_model = new FileBrowserModel(p); if(p->locationType()==0) { QFileSystemModel* model = new QFileSystemModel(); model->setRootPath(p->path()); m_model->setFileModel(model); } else { FTPFileModel* model = new FTPFileModel(p); m_model->setFileModel(model); } static_cast<ProjectFilesBrowser*>(m_view->mainWidget())->setModel(m_model->fileModel()); }
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { setupUi(this); menuView->addAction(fileBrowserDock->toggleViewAction()); menuView->addAction(informationDock->toggleViewAction()); menuView->addAction(drawingDock->toggleViewAction()); // Load and initialize palettes _ildaPalette = loadPalette(":/data/ilda.palette"); _pangolinPalette = loadPalette(":/data/pangolin.palette"); _currentPalette = &_ildaPalette; // File browser QFileSystemModel *fsModel = new QFileSystemModel(this); fsModel->setRootPath(QDir::rootPath()); fsModel->setNameFilterDisables(false); fsModel->setNameFilters(QStringList() << "*.ild"); treeView->setModel(fsModel); treeView->header()->setResizeMode(0, QHeaderView::ResizeToContents); //treeView->setSortingEnabled(true); //treeView->sortByColumn(0, Qt::AscendingOrder); treeView->setColumnHidden(2, true); treeView->setColumnHidden(3, true); //treeView->setRootIndex(fsModel->index(QDir::homePath())); // Create the connections connect(actionOpen, SIGNAL(triggered()), this, SLOT(fileOpen())); connect(actionSaveAs, SIGNAL(triggered()), this, SLOT(fileSaveAs())); connect(actionPangolin_palette, SIGNAL(triggered()), SLOT(usePangolinPalette())); connect(actionILDA_palette, SIGNAL(triggered()), SLOT(useILDAPalette())); connect(actionAbout, SIGNAL(triggered()), SLOT(about())); connect(treeView, SIGNAL(clicked(QModelIndex)), SLOT(fileBrowserItemClicked(QModelIndex))); connect(treeView, SIGNAL(doubleClicked(QModelIndex)), SLOT(fileBrowserItemDblClicked(QModelIndex))); connect(normalRadioButton, SIGNAL(clicked()), SLOT(drawModeChanged())); connect(diagnosticRadioButton, SIGNAL(clicked()), SLOT(drawModeChanged())); // restore settings readSettings(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QSplitter splitter; QTreeView *tree = new QTreeView(&splitter); QListView *list = new QListView(&splitter); QFileSystemModel *model = new QFileSystemModel(&app); model->setRootPath(QDir::root().path()); tree->setModel(model); list->setModel(model); list->setRootIndex(model->index(".")); splitter.show(); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QFileSystemModel model; model.setRootPath(""); QTreeView tree; tree.setModel(&model); // Demonstrating look and feel features tree.setAnimated(false); tree.setIndentation(20); tree.setSortingEnabled(true); tree.setWindowTitle(QObject::tr("Dir View")); tree.resize(640, 480); tree.show(); return app.exec(); }
void Test_FileSystem_MVC() { QSplitter* splitter = new QSplitter;//two widget QFileSystemModel* model = new QFileSystemModel; QTreeView* tree = new QTreeView(splitter);//left tree view QListView* list = new QListView(splitter);//right list view splitter->setWindowTitle("Two vies onto the same file system model"); model->setRootPath(QDir::currentPath()); tree->setModel(model);//set model for view tree->setRootIndex(model->index(QDir::currentPath())); list->setModel(model); list->setRootIndex(model->index(QDir::currentPath())); list->setSelectionModel(tree->selectionModel()); splitter->show(); }
/** * Setup the tree view widget. */ void CodeImpSelectPage::setupTreeView() { QFileSystemModel* model = new QFileSystemModel(); model->setRootPath(""); m_fileExtensions << "*.h" << "*.hpp" << "*.hh" << "*.hxx" << "*.H"; //:TODO set according to the current language! model->setNameFilters(m_fileExtensions); ui_treeView->setModel(model); ui_treeView->setIndentation(20); ui_treeView->setColumnWidth(0, 200); ui_treeView->setSortingEnabled(true); ui_treeView->setWindowTitle(i18n("File System Model")); if (s_recentPath.isEmpty()) { ui_treeView->setCurrentIndex(model->index(QDir::currentPath())); } else { ui_treeView->setCurrentIndex(model->index(s_recentPath)); } ui_treeView->show(); }
void DataSourceSelector::setup() { _fileEdit = new QLineEdit(this); _fileButton = new QToolButton(this); int h = fontMetrics().lineSpacing()*4/3; _fileEdit->setFixedHeight(h); QHBoxLayout * layout = new QHBoxLayout(this); layout->setMargin(0); layout->addWidget(_fileEdit); layout->addWidget(_fileButton); _fileButton->setFixedSize(h,h); setLayout(layout); //int size = style()->pixelMetric(QStyle::PM_SmallIconSize); _fileButton->setFixedSize(h,h); _fileButton->setIcon(KstGetIcon("kst_changefile")); //qDebug() << "file button small icon size" << size; setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); //connect (_fileEdit, SIGNAL(textChanged(const QString &)), this, SIGNAL(changed(const QString &))); connect (_fileEdit, SIGNAL(textChanged(QString)), this, SLOT(updateFile(QString))); connect (_fileButton, SIGNAL(clicked()), this, SLOT(chooseFile())); QFileSystemModel *dirModel = new QFileSystemModel; dirModel->setFilter(QDir::AllEntries); dirModel->setRootPath(QString('/')); QCompleter *completer = new QCompleter(this); completer->setModel(dirModel); _fileEdit->setCompleter(completer); setFixedHeight(h); }