mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-05 16:55:25 +08:00
6.5.3 clean
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(dirview LANGUAGES CXX)
|
||||
|
||||
if(NOT DEFINED INSTALL_EXAMPLESDIR)
|
||||
set(INSTALL_EXAMPLESDIR "examples")
|
||||
endif()
|
||||
|
||||
set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/itemviews/dirview")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(dirview
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(dirview PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(dirview PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Gui
|
||||
Qt6::Widgets
|
||||
)
|
||||
|
||||
install(TARGETS dirview
|
||||
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
|
||||
)
|
@ -0,0 +1,8 @@
|
||||
QT += widgets
|
||||
requires(qtConfig(treeview))
|
||||
|
||||
SOURCES = main.cpp
|
||||
|
||||
# install
|
||||
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/itemviews/dirview
|
||||
INSTALLS += target
|
62
tests/manual/examples/widgets/itemviews/dirview/main.cpp
Normal file
62
tests/manual/examples/widgets/itemviews/dirview/main.cpp
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright (C) 2020 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileSystemModel>
|
||||
#include <QFileIconProvider>
|
||||
#include <QScreen>
|
||||
#include <QScroller>
|
||||
#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();
|
||||
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()
|
||||
? QString() : parser.positionalArguments().first();
|
||||
|
||||
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);
|
||||
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 = tree.screen()->availableGeometry().size();
|
||||
tree.resize(availableSize / 2);
|
||||
tree.setColumnWidth(0, tree.width() / 3);
|
||||
|
||||
// Make it flickable on touchscreens
|
||||
QScroller::grabGesture(&tree, QScroller::TouchGesture);
|
||||
|
||||
tree.setWindowTitle(QObject::tr("Dir View"));
|
||||
tree.show();
|
||||
|
||||
return app.exec();
|
||||
}
|
Reference in New Issue
Block a user