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 parser; parser.setApplicationDescription("Qt Dir View Example"); parser.addHelpOption(); parser.addVersionOption(); QCommandLineOption dontUseCustomDirectoryIconsOption("c", "Set QFileSystemModel::DontUseCustomDirectoryIcons"); parser.addOption(dontUseCustomDirectoryIconsOption); QCommandLineOption dontWatchOption("w", "Set QFileSystemModel::DontWatch"); parser.addOption(dontWatchOption); parser.addPositionalArgument("directory", "The directory to start in."); parser.process(app); const QString rootPath = parser.positionalArguments().isEmpty()
The example supports a number of command line options. These options include:
QFileSystemModel model; QFileIconProvider iconProvider; model.setIconProvider(&iconProvider); model.setRootPath(""); if (parser.isSet(dontUseCustomDirectoryIconsOption)) model.setOption(QFileSystemModel::DontUseCustomDirectoryIcons); if (parser.isSet(dontWatchOption)) model.setOption(QFileSystemModel::DontWatchForChanges); QTreeView tree; tree.setModel(&model);
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 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.
QScroller::grabGesture(&tree, QScroller::TouchGesture);
Creates a QScroller instance to recognize gestures on touchscreens, so that you can flick the tree view with your finger.
As part of the free Business evaluation, we offer a free welcome call for companies, to talk about your requirements, and how the Felgo SDK & Services can help you. Just sign up and schedule your call.
Sign up now to start your free Business evaluation: