add book
This commit is contained in:
40
Qt6QMLBeginnersCode/9-Dialogs/2-ColorDialog/CMakeLists.txt
Normal file
40
Qt6QMLBeginnersCode/9-Dialogs/2-ColorDialog/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(2-ColorDialog VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick QuickControls2)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app2-ColorDialog
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app2-ColorDialog
|
||||
URI 2-ColorDialog
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app2-ColorDialog 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(app2-ColorDialog
|
||||
PRIVATE Qt6::Quick Qt6::QuickControls2
|
||||
)
|
||||
|
||||
install(TARGETS app2-ColorDialog
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
48
Qt6QMLBeginnersCode/9-Dialogs/2-ColorDialog/Main.qml
Normal file
48
Qt6QMLBeginnersCode/9-Dialogs/2-ColorDialog/Main.qml
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Dialogs
|
||||
import QtQuick.Controls
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("ColorDialog")
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
anchors.centerIn: parent
|
||||
|
||||
Button{
|
||||
text : "Choose Color"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onClicked: {
|
||||
colorDialogId.open()
|
||||
}
|
||||
}
|
||||
Rectangle{
|
||||
width: 200
|
||||
height: 200
|
||||
id : rectangleId
|
||||
border.color: "black"
|
||||
border.width: 8
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
ColorDialog{
|
||||
id: colorDialogId
|
||||
title: "Please choose a color"
|
||||
onAccepted: {
|
||||
console.log("User chose color: "+ selectedColor)
|
||||
rectangleId.color = selectedColor
|
||||
|
||||
}
|
||||
onRejected: {
|
||||
console.log("User rejected dialog")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
Qt6QMLBeginnersCode/9-Dialogs/2-ColorDialog/main.cpp
Normal file
21
Qt6QMLBeginnersCode/9-Dialogs/2-ColorDialog/main.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickStyle>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QQuickStyle::setStyle("Fusion");
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("2-ColorDialog", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
40
Qt6QMLBeginnersCode/9-Dialogs/3-FileDialog/CMakeLists.txt
Normal file
40
Qt6QMLBeginnersCode/9-Dialogs/3-FileDialog/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(3-FileDialog 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(app3-FileDialog
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app3-FileDialog
|
||||
URI 3-FileDialog
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app3-FileDialog 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(app3-FileDialog
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app3-FileDialog
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
70
Qt6QMLBeginnersCode/9-Dialogs/3-FileDialog/Main.qml
Normal file
70
Qt6QMLBeginnersCode/9-Dialogs/3-FileDialog/Main.qml
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Dialogs
|
||||
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("FileDialog")
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
anchors.centerIn: parent
|
||||
|
||||
Button{
|
||||
text: "Choose File"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onClicked: {
|
||||
fileDialogId.open()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: textId
|
||||
text: "Use hasn't chosen yet"
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
FileDialog{
|
||||
id: fileDialogId
|
||||
title: "Choose File"
|
||||
nameFilters: ["Text files (*.txt)", "HTML files (*.html *.htm)", "Images (*.jpg *.png)"]
|
||||
|
||||
onAccepted: {
|
||||
textId.text = selectedFile
|
||||
}
|
||||
|
||||
onRejected: {
|
||||
textId.text = "Dialog rejected"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
20
Qt6QMLBeginnersCode/9-Dialogs/3-FileDialog/main.cpp
Normal file
20
Qt6QMLBeginnersCode/9-Dialogs/3-FileDialog/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("3-FileDialog", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
40
Qt6QMLBeginnersCode/9-Dialogs/4-FolderDialog/CMakeLists.txt
Normal file
40
Qt6QMLBeginnersCode/9-Dialogs/4-FolderDialog/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(4-FolderDialog 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(app4-FolderDialog
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app4-FolderDialog
|
||||
URI 4-FolderDialog
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app4-FolderDialog 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(app4-FolderDialog
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app4-FolderDialog
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
70
Qt6QMLBeginnersCode/9-Dialogs/4-FolderDialog/Main.qml
Normal file
70
Qt6QMLBeginnersCode/9-Dialogs/4-FolderDialog/Main.qml
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Dialogs
|
||||
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("FolderDialog")
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
anchors.centerIn: parent
|
||||
|
||||
Button{
|
||||
text: "Choose Folder"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onClicked: {
|
||||
folderDialogId.open()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: textId
|
||||
text : "Use hasn't chosen yet"
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
FolderDialog{
|
||||
id: folderDialogId
|
||||
title: "Choose Folder"
|
||||
|
||||
onAccepted: {
|
||||
textId.text = selectedFolder
|
||||
|
||||
}
|
||||
|
||||
onRejected: {
|
||||
textId.text = "Dialog rejected"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
19
Qt6QMLBeginnersCode/9-Dialogs/4-FolderDialog/main.cpp
Normal file
19
Qt6QMLBeginnersCode/9-Dialogs/4-FolderDialog/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// 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("4-FolderDialog", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
40
Qt6QMLBeginnersCode/9-Dialogs/5-FontDialog/CMakeLists.txt
Normal file
40
Qt6QMLBeginnersCode/9-Dialogs/5-FontDialog/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(5-FontDialog VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick QuickControls2)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app5-FontDialog
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app5-FontDialog
|
||||
URI 5-FontDialog
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app5-FontDialog 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(app5-FontDialog
|
||||
PRIVATE Qt6::Quick Qt6::QuickControls2
|
||||
)
|
||||
|
||||
install(TARGETS app5-FontDialog
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
76
Qt6QMLBeginnersCode/9-Dialogs/5-FontDialog/Main.qml
Normal file
76
Qt6QMLBeginnersCode/9-Dialogs/5-FontDialog/Main.qml
Normal file
@@ -0,0 +1,76 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Window
|
||||
import QtQuick.Dialogs
|
||||
import QtQuick.Controls
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("FontDialog Demo")
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
anchors.centerIn: parent
|
||||
|
||||
Button{
|
||||
text: "Change Font"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onClicked: {
|
||||
fontDialogId.open()
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: textId
|
||||
text: "Hello World"
|
||||
}
|
||||
|
||||
FontDialog{
|
||||
id: fontDialogId
|
||||
title: "Choose Font"
|
||||
currentFont: Qt.font({ family: "Arial", pointSize: 24, weight: Font.Normal })
|
||||
|
||||
onAccepted: {
|
||||
console.log("Chose font: "+selectedFont)
|
||||
textId.font = fontDialogId.selectedFont
|
||||
}
|
||||
onRejected: {
|
||||
console.log("Dialog rejected")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
22
Qt6QMLBeginnersCode/9-Dialogs/5-FontDialog/main.cpp
Normal file
22
Qt6QMLBeginnersCode/9-Dialogs/5-FontDialog/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickStyle>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QQuickStyle::setStyle("Fusion");
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("5-FontDialog", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
40
Qt6QMLBeginnersCode/9-Dialogs/6-MessageDialog/CMakeLists.txt
Normal file
40
Qt6QMLBeginnersCode/9-Dialogs/6-MessageDialog/CMakeLists.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(6-MessageDialog VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick QuickControls2)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app6-MessageDialog
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app6-MessageDialog
|
||||
URI 6-MessageDialog
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app6-MessageDialog 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-MessageDialog
|
||||
PRIVATE Qt6::Quick Qt6::QuickControls2
|
||||
)
|
||||
|
||||
install(TARGETS app6-MessageDialog
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
34
Qt6QMLBeginnersCode/9-Dialogs/6-MessageDialog/Main.qml
Normal file
34
Qt6QMLBeginnersCode/9-Dialogs/6-MessageDialog/Main.qml
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Dialogs
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("MessageDialog ")
|
||||
|
||||
Button{
|
||||
text: "Push Me"
|
||||
onClicked: {
|
||||
messageDialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
MessageDialog {
|
||||
id: messageDialog
|
||||
title: "Message"
|
||||
text: "Lie down and watch the sky."
|
||||
buttons: MessageDialog.Ok | MessageDialog.Close
|
||||
onAccepted: {
|
||||
console.log("Dialog accepted.")
|
||||
}
|
||||
onRejected: {
|
||||
console.log("Dialog rejected")
|
||||
}
|
||||
}
|
||||
}
|
||||
22
Qt6QMLBeginnersCode/9-Dialogs/6-MessageDialog/main.cpp
Normal file
22
Qt6QMLBeginnersCode/9-Dialogs/6-MessageDialog/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickStyle>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QQuickStyle::setStyle("Fusion");
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("6-MessageDialog", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
41
Qt6QMLBeginnersCode/9-Dialogs/7-CustomDialog/CMakeLists.txt
Normal file
41
Qt6QMLBeginnersCode/9-Dialogs/7-CustomDialog/CMakeLists.txt
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(7-CustomDialog VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick QuickControls2)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app7-CustomDialog
|
||||
main.cpp resource.qrc
|
||||
)
|
||||
|
||||
qt_add_qml_module(app7-CustomDialog
|
||||
URI 7-CustomDialog
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml
|
||||
)
|
||||
|
||||
set_target_properties(app7-CustomDialog 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(app7-CustomDialog
|
||||
PRIVATE Qt6::Quick Qt6::QuickControls2
|
||||
)
|
||||
|
||||
install(TARGETS app7-CustomDialog
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
196
Qt6QMLBeginnersCode/9-Dialogs/7-CustomDialog/Main.qml
Normal file
196
Qt6QMLBeginnersCode/9-Dialogs/7-CustomDialog/Main.qml
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Custom Dialogs")
|
||||
|
||||
readonly property int buttonWidth: 300
|
||||
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
width:parent.width
|
||||
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
wrapMode: Label.Wrap
|
||||
horizontalAlignment: Qt.AlignHCenter
|
||||
text: "Dialog is a popup that is mostly used for short-term tasks "
|
||||
+ "and brief communications with the user."
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Message"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: buttonWidth
|
||||
onClicked: messageDialog.open()
|
||||
|
||||
Dialog {
|
||||
id: messageDialog
|
||||
|
||||
x: (parent.width - width) / 2
|
||||
y: (parent.height - height) / 2
|
||||
|
||||
title: "Message"
|
||||
|
||||
Label {
|
||||
text: "Lorem ipsum dolor sit amet..."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Button {
|
||||
id: button
|
||||
text: "Confirmation"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: buttonWidth
|
||||
onClicked: confirmationDialog.open()
|
||||
|
||||
Dialog {
|
||||
id: confirmationDialog
|
||||
|
||||
x: (parent.width - width) / 2
|
||||
y: (parent.height - height) / 2
|
||||
parent: Overlay.overlay
|
||||
|
||||
modal: true
|
||||
title: "Confirmation"
|
||||
standardButtons: Dialog.Yes | Dialog.No
|
||||
|
||||
Column {
|
||||
spacing: 20
|
||||
anchors.fill: parent
|
||||
Label {
|
||||
text: "The document has been modified.\nDo you want to save your changes?"
|
||||
}
|
||||
CheckBox {
|
||||
text: "Do not ask again"
|
||||
anchors.right: parent.right
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Button {
|
||||
text: "Content"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: buttonWidth
|
||||
onClicked: contentDialog.open()
|
||||
|
||||
Dialog {
|
||||
id: contentDialog
|
||||
|
||||
x: (parent.width - width) / 2
|
||||
y: (parent.height - height) / 2
|
||||
width: Math.min(parent.width, parent.height) / 3 * 2
|
||||
//contentHeight: logo.height * 2 // This causes a binding loop
|
||||
contentHeight: parent.height/2 // This doesn't cause the binding loop.
|
||||
parent: Overlay.overlay
|
||||
|
||||
modal: true
|
||||
title: "Content"
|
||||
standardButtons: Dialog.Close
|
||||
|
||||
Flickable {
|
||||
id: flickable
|
||||
clip: true
|
||||
anchors.fill: parent
|
||||
contentHeight: column.height
|
||||
|
||||
Column {
|
||||
id: column
|
||||
spacing: 20
|
||||
width: parent.width
|
||||
|
||||
Image {
|
||||
id: logo
|
||||
width: parent.width / 2
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
fillMode: Image.PreserveAspectFit
|
||||
source: "qrc:/images/LearnQtLogo.png"
|
||||
}
|
||||
|
||||
Label {
|
||||
width: parent.width
|
||||
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc finibus "
|
||||
+ "in est quis laoreet. Interdum et malesuada fames ac ante ipsum primis "
|
||||
+ "in faucibus. Curabitur eget justo sollicitudin enim faucibus bibendum. "
|
||||
+ "Suspendisse potenti. Vestibulum cursus consequat mauris id sollicitudin. "
|
||||
+ "Duis facilisis hendrerit consectetur. Curabitur sapien tortor, efficitur "
|
||||
+ "id auctor nec, efficitur et nisl. Ut venenatis eros in nunc placerat, "
|
||||
+ "eu aliquam enim suscipit."
|
||||
wrapMode: Label.Wrap
|
||||
}
|
||||
}
|
||||
|
||||
ScrollIndicator.vertical: ScrollIndicator {
|
||||
parent: contentDialog.contentItem
|
||||
anchors.top: flickable.top
|
||||
anchors.bottom: flickable.bottom
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: -contentDialog.rightPadding + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Button {
|
||||
text: "Input"
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: buttonWidth
|
||||
onClicked: inputDialog.open()
|
||||
|
||||
Dialog {
|
||||
id: inputDialog
|
||||
|
||||
x: (parent.width - width) / 2
|
||||
y: (parent.height - height) / 2
|
||||
parent: Overlay.overlay
|
||||
|
||||
focus: true
|
||||
modal: true
|
||||
title: "Input"
|
||||
standardButtons: Dialog.Ok | Dialog.Cancel
|
||||
|
||||
ColumnLayout {
|
||||
spacing: 20
|
||||
anchors.fill: parent
|
||||
Label {
|
||||
elide: Label.ElideRight
|
||||
text: "Please enter the credentials:"
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
TextField {
|
||||
focus: true
|
||||
placeholderText: "Username"
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
TextField {
|
||||
placeholderText: "Password"
|
||||
echoMode: TextField.PasswordEchoOnEdit
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 6.2 KiB |
22
Qt6QMLBeginnersCode/9-Dialogs/7-CustomDialog/main.cpp
Normal file
22
Qt6QMLBeginnersCode/9-Dialogs/7-CustomDialog/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickStyle>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QQuickStyle::setStyle("Material");
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("7-CustomDialog", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>images/LearnQtLogo.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
Reference in New Issue
Block a user