add book
This commit is contained in:
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();
|
||||
}
|
||||
Reference in New Issue
Block a user