diff options
Diffstat (limited to 'examples/quick/models/objectlistmodel')
5 files changed, 46 insertions, 39 deletions
diff --git a/examples/quick/models/objectlistmodel/CMakeLists.txt b/examples/quick/models/objectlistmodel/CMakeLists.txt index 23b4cf7ed5..8dbee3ae0b 100644 --- a/examples/quick/models/objectlistmodel/CMakeLists.txt +++ b/examples/quick/models/objectlistmodel/CMakeLists.txt @@ -1,13 +1,12 @@ # Generated from objectlistmodel.pro. -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.16) project(objectlistmodel LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) if(NOT DEFINED INSTALL_EXAMPLESDIR) set(INSTALL_EXAMPLESDIR "examples") @@ -15,20 +14,13 @@ endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/models/objectlistmodel") -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Qml) -find_package(Qt6 COMPONENTS Quick) +find_package(Qt6 COMPONENTS Core Gui Qml Quick) -qt_add_executable(objectlistmodel - dataobject.cpp dataobject.h +qt_add_executable(objectlistmodelexample WIN32 MACOSX_BUNDLE + dataobject.cpp main.cpp ) -set_target_properties(objectlistmodel PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(objectlistmodel PUBLIC +target_link_libraries(objectlistmodelexample PUBLIC Qt::Core Qt::Gui Qt::Qml @@ -37,18 +29,14 @@ target_link_libraries(objectlistmodel PUBLIC # Resources: -set(objectlistmodel_resource_files - "view.qml" -) - -qt6_add_resources(objectlistmodel "objectlistmodel" - PREFIX - "/" - FILES - ${objectlistmodel_resource_files} +qt_add_qml_module(objectlistmodelexample + URI objectlistmodel + VERSION 1.0 + QML_FILES + "view.qml" ) -install(TARGETS objectlistmodel +install(TARGETS objectlistmodelexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/quick/models/objectlistmodel/dataobject.cpp b/examples/quick/models/objectlistmodel/dataobject.cpp index 6963d75c42..354b9d74b4 100644 --- a/examples/quick/models/objectlistmodel/dataobject.cpp +++ b/examples/quick/models/objectlistmodel/dataobject.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. diff --git a/examples/quick/models/objectlistmodel/main.cpp b/examples/quick/models/objectlistmodel/main.cpp index 8fbe7c183c..5d406f356c 100644 --- a/examples/quick/models/objectlistmodel/main.cpp +++ b/examples/quick/models/objectlistmodel/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the demonstration applications of the Qt Toolkit. @@ -49,6 +49,7 @@ ****************************************************************************/ #include <QGuiApplication> +#include <QList> #include <qqmlengine.h> #include <qqmlcontext.h> @@ -68,21 +69,36 @@ int main(int argc, char ** argv) { QGuiApplication app(argc, argv); - QList<QObject *> dataList = { - new DataObject("Item 1", "red"), - new DataObject("Item 2", "green"), - new DataObject("Item 3", "blue"), - new DataObject("Item 4", "yellow") - }; + const QStringList colorList = {"red", + "green", + "blue", + "yellow"}; + + const QStringList moduleList = {"Core", "GUI", "Multimedia", "Multimedia Widgets", "Network", + "QML", "Quick", "Quick Controls", "Quick Dialogs", + "Quick Layouts", "Quick Test", "SQL", "Widgets", "3D", + "Android Extras", "Bluetooth", "Concurrent", "D-Bus", + "Gamepad", "Graphical Effects", "Help", "Image Formats", + "Location", "Mac Extras", "NFC", "OpenGL", "Platform Headers", + "Positioning", "Print Support", "Purchasing", "Quick Extras", + "Quick Timeline", "Quick Widgets", "Remote Objects", "Script", + "SCXML", "Script Tools", "Sensors", "Serial Bus", + "Serial Port", "Speech", "SVG", "UI Tools", "WebEngine", + "WebSockets", "WebView", "Windows Extras", "XML", + "XML Patterns", "Charts", "Network Authorization", + "Virtual Keyboard", "Quick 3D", "Quick WebGL"}; + + QList<QObject *> dataList; + for (const QString &module : moduleList) + dataList.append(new DataObject("Qt " + module, colorList.at(rand() % colorList.length()))); QQuickView view; view.setResizeMode(QQuickView::SizeRootObjectToView); view.setInitialProperties({{ "model", QVariant::fromValue(dataList) }}); //![0] - view.setSource(QUrl("qrc:view.qml")); + view.setSource(QUrl("qrc:/objectlistmodel/view.qml")); view.show(); return app.exec(); } - diff --git a/examples/quick/models/objectlistmodel/objectlistmodel.qrc b/examples/quick/models/objectlistmodel/objectlistmodel.qrc index 17e9301471..a6e8cffb08 100644 --- a/examples/quick/models/objectlistmodel/objectlistmodel.qrc +++ b/examples/quick/models/objectlistmodel/objectlistmodel.qrc @@ -1,5 +1,5 @@ <!DOCTYPE RCC><RCC version="1.0"> -<qresource> +<qresource prefix="/objectlistmodel"> <file>view.qml</file> </qresource> </RCC> diff --git a/examples/quick/models/objectlistmodel/view.qml b/examples/quick/models/objectlistmodel/view.qml index ba0c905e1e..4adc8ca84f 100644 --- a/examples/quick/models/objectlistmodel/view.qml +++ b/examples/quick/models/objectlistmodel/view.qml @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2017 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. @@ -48,19 +48,22 @@ ** ****************************************************************************/ -import QtQuick 2.0 +import QtQuick +import QtQuick.Controls //![0] ListView { - width: 100; height: 100 + id: listview + width: 200; height: 320 required model + ScrollBar.vertical: ScrollBar { } delegate: Rectangle { + width: listview.width; height: 25 + required color required property string name - height: 25 - width: 100 Text { text: parent.name } } } |