diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-03-05 10:08:11 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-03-06 18:09:42 +0000 |
commit | d326952b51ccd8e92f54d9faee12475060ab0968 (patch) | |
tree | f119785d03b93c52e776536e95f08008be058590 /examples/widgets | |
parent | ed42bf8c0562ce625ebf7bb3e6b0624da5a1d7ec (diff) |
Polish the Dir View example.
Add a command line parser so that the directory can be specified.
Resize depending on screen size and make first (name) column larger.
Change-Id: Ied5823b4e8f50345aae792628fb610b8604e37d3
Reviewed-by: Topi Reiniƶ <topi.reinio@digia.com>
Diffstat (limited to 'examples/widgets')
-rw-r--r-- | examples/widgets/itemviews/dirview/main.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/examples/widgets/itemviews/dirview/main.cpp b/examples/widgets/itemviews/dirview/main.cpp index bc1b8a5d7b..abca413325 100644 --- a/examples/widgets/itemviews/dirview/main.cpp +++ b/examples/widgets/itemviews/dirview/main.cpp @@ -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(); |