Dir View Example | Qt Widgets 5.15.18 (original) (raw)

This example demonstrates the usage of a tree view, and smooth flicking on a touchscreen.

The Dir View example shows a tree view of the local file system. It uses the QFileSystemModel class to provide file and directory information.

[QCommandLineParser](qcommandlineparser.html) parser;
parser.setApplicationDescription("Qt Dir View Example");
parser.addHelpOption();
parser.addVersionOption();
[QCommandLineOption](qcommandlineoption.html) dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons");
parser.addOption(dontUseCustomDirectoryIconsOption);
[QCommandLineOption](qcommandlineoption.html) dontWatchOption("w", "Set QFileSystemModel::DontWatch");
parser.addOption(dontWatchOption);
parser.addPositionalArgument("directory", "The directory to start in.");
parser.process(app);
const [QString](qstring.html) rootPath = parser.positionalArguments().isEmpty()

The example supports a number of command line options. These options include:

Declares model as data model for reading the local filesystem. model.setRootPath("") sets the current folder as the folder from which model will start reading. QTreeView object tree visualizes the filesystem in a tree structure.

tree.setAnimated(false);
tree.setIndentation(20);
tree.setSortingEnabled(true);
const [QSize](qsize.html) availableSize = tree.screen()->availableGeometry().size();
tree.resize(availableSize / 2);
tree.setColumnWidth(0, tree.width() / 3);

Sets layout options for animation, indentation, sorting, and sizing of the filesystem tree.

Creates a QScroller instance to recognize gestures on touchscreens, so that you can flick the tree view with your finger.

Example project @ code.qt.io

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.