add book
This commit is contained in:
40
Qt6QMLBeginnersCode/7-Positioning/6-Layouts/CMakeLists.txt
Normal file
40
Qt6QMLBeginnersCode/7-Positioning/6-Layouts/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(6-Layouts VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app6-Layouts
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app6-Layouts
|
||||
URI 6-Layouts
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app6-Layouts PROPERTIES
|
||||
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
|
||||
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
|
||||
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
|
||||
MACOSX_BUNDLE TRUE
|
||||
WIN32_EXECUTABLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(app6-Layouts
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app6-Layouts
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
164
Qt6QMLBeginnersCode/7-Positioning/6-Layouts/Main.qml
Normal file
164
Qt6QMLBeginnersCode/7-Positioning/6-Layouts/Main.qml
Normal file
@@ -0,0 +1,164 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
Window {
|
||||
visible: true
|
||||
width: mGridLayoutId.implicitWidth
|
||||
height: mGridLayoutId.implicitHeight
|
||||
title: qsTr("Layouts")
|
||||
|
||||
GridLayout{
|
||||
id: mGridLayoutId
|
||||
anchors.fill: parent
|
||||
columns: 3
|
||||
layoutDirection: Qt.RightToLeft
|
||||
|
||||
Rectangle {
|
||||
id: topLeftRectId
|
||||
width: 70
|
||||
height: width
|
||||
color: "green"
|
||||
Text{text: "1"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
|
||||
//Showing Layout alignment
|
||||
Layout.alignment: Qt.AlignRight|Qt.AlignTop
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.maximumWidth: 150
|
||||
Layout.maximumHeight: 150
|
||||
}
|
||||
Rectangle {
|
||||
id: topCenterRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "red"
|
||||
Text{text: "2"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.columnSpan: 2
|
||||
}
|
||||
|
||||
//Taking this out because topCenterRectId will span two columns
|
||||
//Rectangle "3" taken out . Its space will be taken by Rectangle "2"
|
||||
/*
|
||||
Rectangle {
|
||||
id: topRightRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "blue"
|
||||
Text{text: "3"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: centerLeftRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "beige"
|
||||
Text{text: "4"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
Layout.rowSpan: 2
|
||||
|
||||
}
|
||||
Rectangle {
|
||||
id: centerCenterRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "pink"
|
||||
Text{text: "5"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
}
|
||||
Rectangle {
|
||||
id: centerRightRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "yellow"
|
||||
Text{text: "6"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Taking this out because the beige centerLeftRectId rectangle will span two rows
|
||||
//Rectangle "7" Taken out. Its space will be taken by Rectangle 4
|
||||
/*
|
||||
|
||||
Rectangle {
|
||||
id: bottomLeftRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "magenta"
|
||||
Text{text: "7"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: bottomCenterRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "yellowgreen"
|
||||
Text{text: "8"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
|
||||
}
|
||||
Rectangle {
|
||||
id: bottomRightRectId
|
||||
width: 100
|
||||
height: width
|
||||
color: "dodgerblue"
|
||||
Text{text: "9"; anchors.centerIn: parent; font.pointSize: 20}
|
||||
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
20
Qt6QMLBeginnersCode/7-Positioning/6-Layouts/main.cpp
Normal file
20
Qt6QMLBeginnersCode/7-Positioning/6-Layouts/main.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("6-Layouts", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user