-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: Add examples/qtquick/fixed_central_widget
Shows how to use a persistent central widget, as we have for QtWidgets.
- Loading branch information
Showing
11 changed files
with
295 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/qtquick/fixed_central_widget/resources_qtquick_example.qrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |