diff options
Diffstat (limited to 'examples/widgets/itemviews/dirview/main.cpp')
-rw-r--r-- | examples/widgets/itemviews/dirview/main.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp index 19551ac717..abca413325 100644 --- a/examples/widgets/itemviews/dirview/main.cpp +++ b/examples/widgets/itemviews/dirview/main.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** @@ -17,8 +17,8 @@ ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. -** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names -** of its contributors may be used to endorse or promote products derived +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** @@ -39,25 +39,45 @@ ****************************************************************************/ #include <QApplication> +#include <QDesktopWidget> #include <QFileSystemModel> #include <QTreeView> +#include <QCommandLineParser> +#include <QCommandLineOption> int main(int argc, char *argv[]) { QApplication app(argc, argv); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + QCommandLineParser parser; + parser.setApplicationDescription("Qt Dir View Example"); + parser.addHelpOption(); + parser.addVersionOption(); + parser.addPositionalArgument("directory", "The directory to start in."); + parser.process(app); + const QString rootPath = parser.positionalArguments().isEmpty() + ? QString() : parser.positionalArguments().first(); + QFileSystemModel model; model.setRootPath(""); QTreeView tree; tree.setModel(&model); + if (!rootPath.isEmpty()) { + const QModelIndex rootIndex = model.index(QDir::cleanPath(rootPath)); + if (rootIndex.isValid()) + tree.setRootIndex(rootIndex); + } // Demonstrating look and feel features tree.setAnimated(false); tree.setIndentation(20); tree.setSortingEnabled(true); + const QSize availableSize = QApplication::desktop()->availableGeometry(&tree).size(); + tree.resize(availableSize / 2); + tree.setColumnWidth(0, tree.width() / 3); tree.setWindowTitle(QObject::tr("Dir View")); - tree.resize(640, 480); tree.show(); return app.exec(); |