Skip to content

Commit

Permalink
examples: Add examples/qtquick/fixed_central_widget
Browse files Browse the repository at this point in the history
Shows how to use a persistent central widget, as we have
for QtWidgets.
  • Loading branch information
iamsergio committed Jun 23, 2024
1 parent 8c1e7ab commit 0833680
Show file tree
Hide file tree
Showing 11 changed files with 295 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/book/src/examples_qtquick_fixed_central_widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# fixed central widget

This example shows a layout with a persistent central widget. This widget can't be detached and
can't be docked over.

View the source in [GitHub](https://github.com/KDAB/KDDockWidgets/blob/main/examples/qtquick/fixed_central_widget/main.qml).
2 changes: 1 addition & 1 deletion examples/qtquick/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ add_subdirectory(mdi)
add_subdirectory(customtitlebar)
add_subdirectory(customtabbar)
add_subdirectory(customseparator)

add_subdirectory(fixed_central_widget)
add_subdirectory(mdi_with_docking)
18 changes: 18 additions & 0 deletions examples/qtquick/fixed_central_widget/Another.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import QtQuick 2.9

Rectangle {
id: root
color: "#0C2D48"
anchors.fill: parent
}
35 changes: 35 additions & 0 deletions examples/qtquick/fixed_central_widget/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This file is part of KDDockWidgets.
#
# SPDX-FileCopyrightText: 2019 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
# Author: Sergio Martins <[email protected]>
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
#
# Contact KDAB at <[email protected]> for commercial licensing options.
#

cmake_minimum_required(VERSION 3.7)
project(qtquick_dockwidgets)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIRS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(NOT TARGET kddockwidgets)
# For the purpose of our example, we're looking for Qt5 or Qt6 KDDW.
# For your own purposes, just chose the one you need.
find_package(KDDockWidgets QUIET)
if(NOT KDDockWidgets_FOUND)
find_package(KDDockWidgets-qt6 REQUIRED)
endif()
endif()

set(RESOURCES_EXAMPLE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/resources_qtquick_example.qrc
${CMAKE_CURRENT_SOURCE_DIR}/../../dockwidgets/resources_example.qrc
)

add_executable(qtquick_fixed_central_widget main.cpp ${RESOURCES_EXAMPLE_SRC})

target_link_libraries(qtquick_fixed_central_widget PRIVATE KDAB::kddockwidgets)
36 changes: 36 additions & 0 deletions examples/qtquick/fixed_central_widget/Guest.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import QtQuick 2.9

Item {
anchors.fill: parent

property alias background: background.source
property alias logo: logo.source


Image {
id: background
anchors.fill: parent
fillMode: Image.PreserveAspectCrop

Image {
id: logo

fillMode: Image.PreserveAspectFit
anchors {
fill: parent
margins: 50
}
}
}
}
19 changes: 19 additions & 0 deletions examples/qtquick/fixed_central_widget/Guest1.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import QtQuick 2.9
import com.kdab.dockwidgets 2.0 as KDDW

Guest {
anchors.fill: parent
background: "qrc:/assets/triangles.png"
logo: "qrc:/assets/KDAB_bubble_white.png"
}
17 changes: 17 additions & 0 deletions examples/qtquick/fixed_central_widget/Guest2.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import QtQuick 2.9

Guest {
anchors.fill: parent
logo: "qrc:/assets/KDAB_bubble_blue.png"
}
18 changes: 18 additions & 0 deletions examples/qtquick/fixed_central_widget/Guest3.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import QtQuick 2.9

Guest {
anchors.fill: parent
background: "qrc:/assets/base.png"
logo: "qrc:/assets/KDAB_bubble_fulcolor.png"
}
51 changes: 51 additions & 0 deletions examples/qtquick/fixed_central_widget/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/


#include <kddockwidgets/Config.h>
#include <kddockwidgets/core/DockRegistry.h>
#include <kddockwidgets/qtquick/ViewFactory.h>
#include <kddockwidgets/qtquick/Platform.h>
#include <kddockwidgets/qtquick/views/DockWidget.h>
#include <kddockwidgets/qtquick/views/MainWindow.h>

#include <QQmlApplicationEngine>
#include <QGuiApplication>
#include <QCommandLineParser>
#include <QQmlContext>

int main(int argc, char *argv[])
{
#ifdef Q_OS_WIN
QGuiApplication::setAttribute(Qt::AA_UseOpenGLES);
#endif
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
QGuiApplication app(argc, argv);

KDDockWidgets::initFrontend(KDDockWidgets::FrontendType::QtQuick);

QCommandLineParser parser;
parser.setApplicationDescription("KDDockWidgets QtQuick example with fixed central area");
parser.addHelpOption();

// Create your engine which loads main.qml. A simple QQuickView would work too.
QQmlApplicationEngine appEngine;
KDDockWidgets::QtQuick::Platform::instance()->setQmlEngine(&appEngine);
appEngine.load((QUrl("qrc:/main.qml")));

// Access the main area we created in QML with DockingArea {}
// auto mainArea = KDDockWidgets::DockRegistry::self()->mainDockingAreas().constFirst();

return app.exec();
}
84 changes: 84 additions & 0 deletions examples/qtquick/fixed_central_widget/main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
This file is part of KDDockWidgets.
SPDX-FileCopyrightText: 2020 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
Author: Sergio Martins <[email protected]>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
Contact KDAB at <[email protected]> for commercial licensing options.
*/

import QtQuick 2.6
import QtQuick.Controls 2.12
import com.kdab.dockwidgets 2.0 as KDDW

ApplicationWindow {
visible: true
width: 1600
height: 800

Rectangle {
id: someTopArea
color: "#CFD4C5"
height: 50
anchors {
left: parent.left
right: parent.right
}
}

KDDW.DockingArea {
id: root
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
top: someTopArea.bottom
}

options: KDDW.KDDockWidgets.MainWindowOption_HasCentralWidget

// Each main layout needs a unique id
uniqueName: "MainLayout-1"

KDDW.DockWidget {
id: dock4
uniqueName: "dock4" // Each dock widget needs a unique id
source: ":/Another.qml"
}

KDDW.DockWidget {
id: dock5
uniqueName: "dock5"
Rectangle {
id: guest
color: "#2E8BC0"
anchors.fill: parent
}
}

KDDW.DockWidget {
id: dock6
uniqueName: "dock6"
Rectangle {
color: "#2E8BC0"
anchors.fill: parent
}
}

Component.onCompleted: {
addDockWidget(dock5, KDDW.KDDockWidgets.Location_OnRight, null, Qt.size(500, 0));
addDockWidget(dock4, KDDW.KDDockWidgets.Location_OnLeft, null, Qt.size(300, 0));
dock5.addDockWidgetAsTab(dock6);
}
}

function toggleDockWidget(dw) {
if (dw.dockWidget.isOpen()) {
dw.dockWidget.close();
} else {
dw.dockWidget.show();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>Guest1.qml</file>
<file>Guest2.qml</file>
<file>Guest3.qml</file>
<file>Guest.qml</file>
<file>Another.qml</file>
</qresource>
</RCC>

0 comments on commit 0833680

Please sign in to comment.