├── README.md ├── 2.GettingStarted ├── 2-12BuildProcessDeclarationsDefinitions │ ├── add.cpp │ ├── main.cpp │ └── CMakeLists.txt ├── 2-2NonQtConsoleApp │ ├── main.cpp │ └── CMakeLists.txt ├── 2-5DataTypes │ └── CMakeLists.txt ├── 2-8Functions │ ├── CMakeLists.txt │ └── main.cpp ├── 2-13GuiIntro │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 2-7GuessNumber │ ├── CMakeLists.txt │ └── main.cpp ├── 2-14NumberGuessGui │ ├── main.cpp │ ├── widget.h │ └── widget.ui ├── 2-4OutputStreams │ ├── CMakeLists.txt │ └── main.cpp ├── 2-6FlowControlLoops │ └── CMakeLists.txt ├── 2-9ClassDeclaration │ ├── CMakeLists.txt │ └── main.cpp ├── 2-10ClassConstructors │ ├── CMakeLists.txt │ └── main.cpp ├── 2-11ClassesMultipleFiles │ ├── box.cpp │ ├── box.h │ ├── CMakeLists.txt │ ├── rectangle.h │ ├── main.cpp │ └── rectangle.cpp └── 2-3QtConsoleApp │ ├── main.cpp │ └── CMakeLists.txt ├── 5.ATourOfQtWidgets ├── 5-7QLabel │ ├── resource.qrc │ ├── images │ │ └── minions.png │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 5-17MenusToolbarsActions │ ├── images │ │ ├── cutIcon.png │ │ ├── aboutIcon.png │ │ ├── copyIcon.png │ │ ├── pasteIcon.png │ │ ├── quitIcon.png │ │ ├── redoIcon.png │ │ ├── undoIcon.png │ │ └── aboutQtIcon.png │ ├── main.cpp │ ├── resource.qrc │ ├── mainwindow.h │ └── mainwindow.cpp ├── 5-11QGridLayout │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ └── CMakeLists.txt ├── 5-14QListWidget │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 5-15QTabWidget │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ └── CMakeLists.txt ├── 5-16QComboBox │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 5-3QMessageBox │ ├── main.cpp │ ├── widget.h │ └── CMakeLists.txt ├── 5-4QPushButton │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ └── CMakeLists.txt ├── 5-5QLineEdit │ ├── main.cpp │ ├── widget.h │ └── CMakeLists.txt ├── 5-6QTextEdit │ ├── main.cpp │ ├── widget.h │ └── CMakeLists.txt ├── 5-8QHBoxLayout │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 5-9QVBoxLayout │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 5-10SizePoliciesStretches │ ├── main.cpp │ ├── widget.cpp │ ├── widget.h │ └── .gitignore ├── 5-12CheckBoxesRadioButtons │ ├── main.cpp │ ├── widget.h │ └── widget.cpp ├── 5-1QWidget │ ├── main.cpp │ ├── rockwidget.h │ └── CMakeLists.txt ├── 5-2QMainWindow │ ├── main.cpp │ ├── mainwindow.h │ ├── mainwindow.cpp │ └── CMakeLists.txt └── 5-13QList │ ├── CMakeLists.txt │ └── main.cpp ├── 8.Styling ├── 8-3ExternalStyleSheets │ ├── resource.qrc │ ├── suredialog.cpp │ ├── suredialog.h │ ├── widget.h │ ├── widget.cpp │ ├── styles │ │ └── style.css │ ├── main.cpp │ ├── suredialog.ui │ └── widget.ui ├── 8-1QPalette │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt └── 8-2StyleSheetInline │ ├── somedialog.cpp │ ├── main.cpp │ ├── somedialog.h │ ├── widget.h │ ├── widget.cpp │ ├── somedialog.ui │ └── widget.ui ├── 7.Resources └── 7-1ResourcesDemo │ ├── images │ ├── cut-fr.png │ ├── cutIcon.png │ ├── minions.png │ ├── aboutIcon.png │ ├── copyIcon.png │ ├── pasteIcon.png │ ├── quitIcon.png │ ├── redoIcon.png │ ├── undoIcon.png │ └── aboutQtIcon.png │ ├── main.cpp │ ├── mainwindow.cpp │ ├── mainwindow.h │ └── resource.qrc ├── 4.SignalsAndSlots ├── 4-1Lambdas │ └── CMakeLists.txt ├── 4-4CaloryCounter │ ├── person.cpp │ ├── main.cpp │ ├── person.h │ ├── widget.h │ └── widget.cpp ├── 4-3WidgetsSignalsSlots │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ └── widget.cpp └── 4-2DifferentConnectionSyntaxes │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ └── widget.ui ├── 6.Dialogs ├── 6-1QDialogDemo │ ├── main.cpp │ ├── widget.h │ ├── infodialog.h │ ├── widget.ui │ ├── infodialog.cpp │ └── widget.cpp ├── 6-3QFileDialog │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ └── CMakeLists.txt ├── 6-4QFontDialog │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── widget.ui │ └── CMakeLists.txt ├── 6-2QDialogButtonBox │ ├── main.cpp │ ├── widget.cpp │ ├── widget.h │ ├── infodialog.h │ ├── widget.ui │ ├── infodialog.ui │ └── infodialog.cpp ├── 6-5QColorDialog │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── CMakeLists.txt │ └── widget.ui └── 6-6QInputDialog │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ ├── widget.cpp │ └── CMakeLists.txt ├── 1.EnvironmentSetup └── 1-1Teaser │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ ├── .gitignore │ ├── CMakeLists.txt │ └── widget.ui ├── 9.Settings └── 9-2QSettingsDemo │ ├── main.cpp │ ├── widget.h │ └── CMakeLists.txt ├── 10.FilesDirectories ├── 10-1QFileDemo │ ├── main.cpp │ ├── widget.h │ └── CMakeLists.txt └── 10-2QDirDemo │ ├── main.cpp │ ├── widget.h │ └── CMakeLists.txt ├── 11.ModelViewArchitecture ├── 11-6QTVQSIM │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ ├── widget.cpp │ └── CMakeLists.txt ├── 11-7QTVQFSM │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ ├── .gitignore │ └── CMakeLists.txt ├── 11-2QListWidgetDemo │ ├── main.cpp │ ├── widget.h │ ├── widget.cpp │ └── widget.ui ├── 11-3QTableWidget │ ├── main.cpp │ ├── widget.h │ └── widget.cpp ├── 11-4QTreeWidget │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ ├── widget.cpp │ └── CMakeLists.txt ├── 11-10CustomTableModel │ ├── main.cpp │ ├── widget.cpp │ ├── widget.h │ └── customtablemodel.h ├── 11-11EditableCustomModel │ ├── main.cpp │ ├── widget.cpp │ ├── widget.h │ └── customtablemodel.h └── 11-5QListViewQStringListModel │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ └── widget.cpp ├── 12.QtNetworkOfferings ├── 12-3JsonClient │ ├── main.cpp │ ├── widget.h │ └── widget.ui └── 12-2QNetworkAccessManagerDemo │ ├── main.cpp │ ├── widget.h │ ├── widget.ui │ └── widget.cpp └── 3.MemoryManagement ├── 3-1HeapStackMemory ├── house.h ├── house.cpp ├── main.cpp └── CMakeLists.txt ├── 3-2SmartPointers ├── house.h ├── house.cpp ├── CMakeLists.txt └── main.cpp └── 3-3QtParentChildRelationship ├── house.h ├── house.cpp ├── CMakeLists.txt └── main.cpp /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/README.md -------------------------------------------------------------------------------- /2.GettingStarted/2-12BuildProcessDeclarationsDefinitions/add.cpp: -------------------------------------------------------------------------------- 1 | //Definition 2 | double add (double a, double b){ 3 | return a + b; 4 | } 5 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/minions.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | styles/style.css 4 | 5 | 6 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/images/minions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-7QLabel/images/minions.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/cut-fr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/cut-fr.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/cutIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/cutIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/minions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/minions.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/aboutIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/aboutIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/copyIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/copyIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/pasteIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/pasteIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/quitIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/quitIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/redoIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/redoIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/undoIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/undoIcon.png -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/images/aboutQtIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/7.Resources/7-1ResourcesDemo/images/aboutQtIcon.png -------------------------------------------------------------------------------- /2.GettingStarted/2-2NonQtConsoleApp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | std::cout << "Hello World. How are you doing!" << std::endl; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/cutIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/cutIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/aboutIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/aboutIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/copyIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/copyIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/pasteIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/pasteIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/quitIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/quitIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/redoIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/redoIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/undoIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/undoIcon.png -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/aboutQtIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rutura/Qt-6-C-GUI-Development-for-Beginners/HEAD/5.ATourOfQtWidgets/5-17MenusToolbarsActions/images/aboutQtIcon.png -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-1Lambdas/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(4-1Lambdas LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(4-1Lambdas main.cpp) 9 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-4CaloryCounter/person.cpp: -------------------------------------------------------------------------------- 1 | #include "person.h" 2 | 3 | void Person::setWeight(double weight) 4 | { 5 | if (m_weight != weight) { 6 | m_weight = weight; 7 | emit weightChanged(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /2.GettingStarted/2-5DataTypes/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-5DataTypes LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-5DataTypes main.cpp) 9 | -------------------------------------------------------------------------------- /2.GettingStarted/2-8Functions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-8Functions LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-8Functions main.cpp) 9 | -------------------------------------------------------------------------------- /6.Dialogs/6-1QDialogDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /6.Dialogs/6-3QFileDialog/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /6.Dialogs/6-4QFontDialog/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /8.Styling/8-1QPalette/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /1.EnvironmentSetup/1-1Teaser/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /2.GettingStarted/2-13GuiIntro/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /2.GettingStarted/2-7GuessNumber/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-7GuessNumber LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-7GuessNumber main.cpp) 9 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /6.Dialogs/6-5QColorDialog/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /6.Dialogs/6-6QInputDialog/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /9.Settings/9-2QSettingsDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /10.FilesDirectories/10-1QFileDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /10.FilesDirectories/10-2QDirDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-4CaloryCounter/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-11QGridLayout/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-14QListWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-15QTabWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-16QComboBox/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-3QMessageBox/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-4QPushButton/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-5QLineEdit/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-6QTextEdit/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-8QHBoxLayout/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-9QVBoxLayout/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-6QTVQSIM/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-7QTVQFSM/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-3JsonClient/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /2.GettingStarted/2-14NumberGuessGui/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /2.GettingStarted/2-4OutputStreams/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-4OutputStreams LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-4OutputStreams main.cpp) 9 | -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-2QListWidgetDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-3QTableWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-4QTreeWidget/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /2.GettingStarted/2-2NonQtConsoleApp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-2NonQtConsoleApp LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-2NonQtConsoleApp main.cpp) 9 | -------------------------------------------------------------------------------- /2.GettingStarted/2-6FlowControlLoops/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-6FlowControlLoops LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-6FlowControlLoops main.cpp) 9 | -------------------------------------------------------------------------------- /2.GettingStarted/2-9ClassDeclaration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-9ClassDeclaration LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-9ClassDeclaration main.cpp) 9 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-3WidgetsSignalsSlots/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-10SizePoliciesStretches/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-10CustomTableModel/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-11EditableCustomModel/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-2DifferentConnectionSyntaxes/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-12CheckBoxesRadioButtons/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-5QListViewQStringListModel/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-2QNetworkAccessManagerDemo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /2.GettingStarted/2-10ClassConstructors/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-10ClassConstructors LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-10ClassConstructors main.cpp) 9 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-3QMessageBox/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = nullptr); 12 | ~Widget(); 13 | }; 14 | #endif // WIDGET_H 15 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-4QPushButton/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = nullptr); 12 | ~Widget(); 13 | }; 14 | #endif // WIDGET_H 15 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-5QLineEdit/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = nullptr); 12 | ~Widget(); 13 | }; 14 | #endif // WIDGET_H 15 | -------------------------------------------------------------------------------- /2.GettingStarted/2-11ClassesMultipleFiles/box.cpp: -------------------------------------------------------------------------------- 1 | #include "box.h" 2 | 3 | Box::Box(int w, int l, int h):m_r(w,l),m_height(h) // Initializer list 4 | { 5 | std::cout << "Para Constructor Called" << std::endl; 6 | } 7 | int Box::get_volume() 8 | { 9 | return m_r.get_area() * m_height; 10 | } 11 | -------------------------------------------------------------------------------- /2.GettingStarted/2-12BuildProcessDeclarationsDefinitions/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //Declaration 4 | double add (double a, double b); 5 | 6 | int main() 7 | { 8 | auto result = add(10,20); 9 | std::cout << "result : " << result << std::endl; 10 | return 0; 11 | } 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-10SizePoliciesStretches/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | Widget::~Widget() 12 | { 13 | delete ui; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-1QWidget/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | RockWidget w; 10 | w.setWindowTitle("Rock Widget"); 11 | w.show(); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/somedialog.cpp: -------------------------------------------------------------------------------- 1 | #include "somedialog.h" 2 | #include "ui_somedialog.h" 3 | 4 | SomeDialog::SomeDialog(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::SomeDialog) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SomeDialog::~SomeDialog() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/suredialog.cpp: -------------------------------------------------------------------------------- 1 | #include "suredialog.h" 2 | #include "ui_suredialog.h" 3 | 4 | SureDialog::SureDialog(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::SureDialog) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | SureDialog::~SureDialog() 12 | { 13 | delete ui; 14 | } 15 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-2QMainWindow/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include "mainwindow.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | MainWindow w; 10 | w.setWindowTitle("Our Very Own main window"); 11 | w.show(); 12 | 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /2.GettingStarted/2-12BuildProcessDeclarationsDefinitions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-12BuildProcessDeclarationsDefinitions LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-12BuildProcessDeclarationsDefinitions main.cpp add.cpp) 9 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-6QTextEdit/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = nullptr); 12 | ~Widget(); 13 | 14 | private : 15 | void setupUi(); 16 | }; 17 | #endif // WIDGET_H 18 | -------------------------------------------------------------------------------- /2.GettingStarted/2-11ClassesMultipleFiles/box.h: -------------------------------------------------------------------------------- 1 | #ifndef BOX_H 2 | #define BOX_H 3 | 4 | #include 5 | #include "rectangle.h" 6 | 7 | //Box class 8 | class Box 9 | { 10 | public: 11 | Box(int w, int l, int h); 12 | int get_volume(); 13 | 14 | private: 15 | Rectangle m_r; 16 | int m_height; 17 | }; 18 | 19 | 20 | 21 | 22 | 23 | #endif // BOX_H 24 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | 9 | //Set stylesheet to entire application 10 | //a.setStyleSheet("QPushButton{background-color : yellow; color : red;}"); 11 | Widget w; 12 | w.show(); 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-1QWidget/rockwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef ROCKWIDGET_H 2 | #define ROCKWIDGET_H 3 | 4 | #include 5 | 6 | class RockWidget : public QWidget 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit RockWidget(QWidget *parent = nullptr); 11 | 12 | private slots: 13 | void button_clicked(); 14 | private: 15 | QSize sizeHint() const; 16 | }; 17 | 18 | #endif // ROCKWIDGET_H 19 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | }; 21 | #endif // WIDGET_H 22 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-11QGridLayout/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | }; 21 | #endif // WIDGET_H 22 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-8QHBoxLayout/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | }; 21 | #endif // WIDGET_H 22 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-9QVBoxLayout/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | }; 21 | #endif // WIDGET_H 22 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-4CaloryCounter/person.h: -------------------------------------------------------------------------------- 1 | #ifndef PERSON_H 2 | #define PERSON_H 3 | 4 | #include 5 | 6 | class Person : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | double weight() const {return m_weight;} 11 | void setWeight(double weight); 12 | 13 | signals: 14 | void weightChanged(); 15 | 16 | private: 17 | double m_weight=0.0; 18 | }; 19 | 20 | #endif // PERSON_H 21 | -------------------------------------------------------------------------------- /2.GettingStarted/2-11ClassesMultipleFiles/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-11ClassesMultipleFiles LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | add_executable(2-11ClassesMultipleFiles 9 | main.cpp 10 | rectangle.h 11 | box.h 12 | rectangle.cpp 13 | box.cpp) 14 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-10SizePoliciesStretches/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private: 19 | Ui::Widget *ui; 20 | }; 21 | #endif // WIDGET_H 22 | -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "./ui_mainwindow.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent) 6 | , ui(new Ui::MainWindow) 7 | { 8 | ui->setupUi(this); 9 | QPixmap pix(":/images/minions.png"); 10 | ui->label->setPixmap(pix.scaled(300,300)); 11 | } 12 | 13 | MainWindow::~MainWindow() 14 | { 15 | delete ui; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/somedialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SOMEDIALOG_H 2 | #define SOMEDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SomeDialog; 8 | } 9 | 10 | class SomeDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SomeDialog(QWidget *parent = nullptr); 16 | ~SomeDialog(); 17 | 18 | private: 19 | Ui::SomeDialog *ui; 20 | }; 21 | 22 | #endif // SOMEDIALOG_H 23 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/suredialog.h: -------------------------------------------------------------------------------- 1 | #ifndef SUREDIALOG_H 2 | #define SUREDIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class SureDialog; 8 | } 9 | 10 | class SureDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit SureDialog(QWidget *parent = nullptr); 16 | ~SureDialog(); 17 | 18 | private: 19 | Ui::SureDialog *ui; 20 | }; 21 | 22 | #endif // SUREDIALOG_H 23 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-1HeapStackMemory/house.h: -------------------------------------------------------------------------------- 1 | #ifndef HOUSE_H 2 | #define HOUSE_H 3 | 4 | #include 5 | 6 | class House : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit House(QObject *parent = nullptr,const QString &descr =""); 11 | ~House();//Destructor : Called when the object dies 12 | void print_info()const; 13 | 14 | private : 15 | QString m_descr; 16 | }; 17 | 18 | #endif // HOUSE_H 19 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-2SmartPointers/house.h: -------------------------------------------------------------------------------- 1 | #ifndef HOUSE_H 2 | #define HOUSE_H 3 | 4 | #include 5 | 6 | class House : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit House(QObject *parent = nullptr,const QString &descr =""); 11 | ~House();//Destructor : Called when the object dies 12 | void print_info()const; 13 | 14 | private : 15 | QString m_descr; 16 | }; 17 | 18 | #endif // HOUSE_H 19 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-3QtParentChildRelationship/house.h: -------------------------------------------------------------------------------- 1 | #ifndef HOUSE_H 2 | #define HOUSE_H 3 | 4 | #include 5 | 6 | class House : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit House(QObject *parent = nullptr,const QString &descr =""); 11 | ~House();//Destructor : Called when the object dies 12 | void print_info()const; 13 | 14 | private : 15 | QString m_descr; 16 | }; 17 | 18 | #endif // HOUSE_H 19 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-2QMainWindow/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | class MainWindow : public QMainWindow 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MainWindow(QWidget *parent = nullptr); 11 | 12 | signals: 13 | 14 | 15 | // QWidget interface 16 | private: 17 | QSize sizeHint() const; 18 | QAction * quitAction; 19 | }; 20 | 21 | #endif // MAINWINDOW_H 22 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-2SmartPointers/house.cpp: -------------------------------------------------------------------------------- 1 | #include "house.h" 2 | #include 3 | 4 | House::House(QObject *parent, const QString &descr) 5 | : QObject(parent), m_descr((descr)) 6 | { 7 | qDebug() << "House object constructed"; 8 | } 9 | 10 | House::~House() 11 | { 12 | qDebug() << "House object : " << m_descr << " is dying..."; 13 | } 14 | 15 | void House::print_info() const 16 | { 17 | qDebug() << "House : " << m_descr; 18 | } 19 | -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class MainWindow; } 8 | QT_END_NAMESPACE 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private: 19 | Ui::MainWindow *ui; 20 | }; 21 | #endif // MAINWINDOW_H 22 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-1HeapStackMemory/house.cpp: -------------------------------------------------------------------------------- 1 | #include "house.h" 2 | #include 3 | 4 | House::House(QObject *parent, const QString &descr) 5 | : QObject(parent), m_descr((descr)) 6 | { 7 | qDebug() << "House object constructed"; 8 | } 9 | 10 | House::~House() 11 | { 12 | qDebug() << "House object : " << m_descr << " is dying..."; 13 | } 14 | 15 | void House::print_info() const 16 | { 17 | qDebug() << "House : " << m_descr; 18 | } 19 | -------------------------------------------------------------------------------- /2.GettingStarted/2-3QtConsoleApp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | QCoreApplication a(argc, argv); 10 | 11 | qDebug() << "Hello world!"; 12 | qDebug() << "Date:" << QDate::currentDate(); 13 | qDebug() << "Types:" << QString("String") << QChar('x') << QRect(0, 10, 50, 40); 14 | 15 | return a.exec(); 16 | } 17 | -------------------------------------------------------------------------------- /2.GettingStarted/2-11ClassesMultipleFiles/rectangle.h: -------------------------------------------------------------------------------- 1 | #ifndef RECTANGLE_H 2 | #define RECTANGLE_H 3 | 4 | #include 5 | 6 | class Rectangle { 7 | public: 8 | //Constructors 9 | Rectangle(); 10 | Rectangle(int w,int l); 11 | 12 | void setWidth( int width); 13 | void setLength( int length); 14 | int get_area()const; 15 | 16 | private: 17 | int m_width; 18 | int m_length; 19 | }; 20 | 21 | 22 | 23 | #endif // RECTANGLE_H 24 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-3QtParentChildRelationship/house.cpp: -------------------------------------------------------------------------------- 1 | #include "house.h" 2 | #include 3 | 4 | House::House(QObject *parent, const QString &descr) 5 | : QObject(parent), m_descr((descr)) 6 | { 7 | qDebug() << "House object constructed"; 8 | } 9 | 10 | House::~House() 11 | { 12 | qDebug() << "House object : " << m_descr << " is dying..."; 13 | } 14 | 15 | void House::print_info() const 16 | { 17 | qDebug() << "House : " << m_descr; 18 | } 19 | -------------------------------------------------------------------------------- /1.EnvironmentSetup/1-1Teaser/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_submitButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /2.GettingStarted/2-13GuiIntro/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_myButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include "infodialog.h" 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | Widget::~Widget() 13 | { 14 | delete ui; 15 | } 16 | 17 | 18 | void Widget::on_showInfoButton_clicked() 19 | { 20 | InfoDialog * dialog = new InfoDialog(this); 21 | 22 | dialog->exec(); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-3QFileDialog/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_chooseButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-4QFontDialog/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_chooseFontButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-6QInputDialog/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_clickButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_clickButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-15QTabWidget/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_pushButton_3_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-1QDialogDemo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_provideInfoButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_showInfoButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_submitButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-10CustomTableModel/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | model = new CustomTableModel(this); 10 | 11 | 12 | ui->listView->setModel(model); 13 | ui->tableView->setModel(model); 14 | ui->treeView->setModel(model); 15 | } 16 | 17 | Widget::~Widget() 18 | { 19 | delete ui; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-2DifferentConnectionSyntaxes/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots : 19 | void change_text(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-3WidgetsSignalsSlots/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots : 19 | void respond(int value); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-11EditableCustomModel/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | model = new CustomTableModel(this); 10 | 11 | 12 | ui->listView->setModel(model); 13 | ui->tableView->setModel(model); 14 | ui->treeView->setModel(model); 15 | } 16 | 17 | Widget::~Widget() 18 | { 19 | delete ui; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-4QTreeWidget/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_listItemsButton_clicked(); 20 | 21 | private: 22 | Ui::Widget *ui; 23 | }; 24 | #endif // WIDGET_H 25 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/aboutIcon.png 4 | images/aboutQtIcon.png 5 | images/copyIcon.png 6 | images/cutIcon.png 7 | images/pasteIcon.png 8 | images/quitIcon.png 9 | images/redoIcon.png 10 | images/undoIcon.png 11 | 12 | 13 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include "suredialog.h" 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | Widget::~Widget() 13 | { 14 | delete ui; 15 | } 16 | 17 | 18 | void Widget::on_submitButton_clicked() 19 | { 20 | SureDialog * dialog = new SureDialog(this); 21 | 22 | int ret = dialog->exec(); 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-10CustomTableModel/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include "customtablemodel.h" 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | private: 20 | Ui::Widget *ui; 21 | CustomTableModel * model; 22 | }; 23 | #endif // WIDGET_H 24 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-11EditableCustomModel/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include "customtablemodel.h" 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | private: 20 | Ui::Widget *ui; 21 | CustomTableModel * model; 22 | }; 23 | #endif // WIDGET_H 24 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | ui->minionTextLabel->move(100,30); 10 | 11 | QPixmap my_image(":/images/minions.png"); 12 | 13 | ui->imageLabel->move(0,70); 14 | ui->imageLabel->setPixmap(my_image.scaled(400,400)); 15 | 16 | } 17 | 18 | Widget::~Widget() 19 | { 20 | delete ui; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /8.Styling/8-1QPalette/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_activeButton_clicked(); 20 | 21 | void on_disabledButton_clicked(); 22 | 23 | private: 24 | Ui::Widget *ui; 25 | }; 26 | #endif // WIDGET_H 27 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-3QTableWidget/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_listItemsButton_clicked(); 20 | 21 | void on_setItemButton_clicked(); 22 | 23 | private: 24 | Ui::Widget *ui; 25 | }; 26 | #endif // WIDGET_H 27 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-2QListWidgetDemo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_listItemsButton_clicked(); 20 | 21 | void on_addItemButton_clicked(); 22 | 23 | private: 24 | Ui::Widget *ui; 25 | }; 26 | #endif // WIDGET_H 27 | -------------------------------------------------------------------------------- /2.GettingStarted/2-11ClassesMultipleFiles/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "rectangle.h" 3 | #include "box.h" 4 | 5 | //Declaration and definition 6 | double add(double a, double b); 7 | 8 | int main() 9 | { 10 | /* 11 | Rectangle r(10,20); 12 | std::cout << "area : " << r.get_area() << std::endl; 13 | 14 | Box b(10,20,30); 15 | std::cout << "volume : " << b.get_volume() << std::endl; 16 | */ 17 | return 0; 18 | } 19 | 20 | //Definition 21 | double add(double a, double b){ 22 | return a + b; 23 | } 24 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-6QTVQSIM/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | private slots: 20 | void on_readData_clicked(); 21 | 22 | private: 23 | Ui::Widget *ui; 24 | QStandardItemModel * model; 25 | }; 26 | #endif // WIDGET_H 27 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-5QListViewQStringListModel/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | private slots: 20 | void on_showData_clicked(); 21 | 22 | private: 23 | Ui::Widget *ui; 24 | QStringListModel * model; 25 | }; 26 | #endif // WIDGET_H 27 | -------------------------------------------------------------------------------- /2.GettingStarted/2-13GuiIntro/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | #include 5 | 6 | Widget::Widget(QWidget *parent) 7 | : QWidget(parent) 8 | , ui(new Ui::Widget) 9 | { 10 | ui->setupUi(this); 11 | } 12 | 13 | Widget::~Widget() 14 | { 15 | delete ui; 16 | } 17 | 18 | 19 | void Widget::on_myButton_clicked() 20 | { 21 | // qDebug() << "You had to click that button. Didn't you!"; 22 | QMessageBox::information(this, "Message","You had to click that button. Didn't you!"); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /2.GettingStarted/2-4OutputStreams/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | //1.cout 8 | std::cout << "Hello World!" << std::endl; 9 | //2.cerr 10 | std::cerr << "There was an error" << std::endl; 11 | //3.clog 12 | std::clog << "This is a log message" << std::endl; 13 | 14 | //4.cin 15 | std::string name; 16 | std::cout << "Please type in your firstname : "; 17 | std::cin >> name; 18 | 19 | std::cout << "Your firstname is : " << name << std::endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-16QComboBox/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_captureButton_clicked(); 20 | 21 | void on_setButton_clicked(); 22 | 23 | void on_listValuesButton_clicked(); 24 | 25 | private: 26 | Ui::Widget *ui; 27 | }; 28 | #endif // WIDGET_H 29 | -------------------------------------------------------------------------------- /6.Dialogs/6-5QColorDialog/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_textColorButton_clicked(); 20 | 21 | void on_backroundColorButton_clicked(); 22 | 23 | void on_fontButton_clicked(); 24 | 25 | private: 26 | Ui::Widget *ui; 27 | }; 28 | #endif // WIDGET_H 29 | -------------------------------------------------------------------------------- /2.GettingStarted/2-14NumberGuessGui/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_guessButton_clicked(); 20 | void on_startOverButton_clicked(); 21 | 22 | private: 23 | Ui::Widget *ui; 24 | int secret_number; 25 | int guess_number; 26 | }; 27 | #endif // WIDGET_H 28 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-13QList/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(5-13QList LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) 16 | 17 | add_executable(5-13QList 18 | main.cpp 19 | ) 20 | target_link_libraries(5-13QList Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-14QListWidget/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_addItemButton_clicked(); 20 | 21 | void on_removeItemButton_clicked(); 22 | 23 | void on_selectedItemsButton_clicked(); 24 | 25 | private: 26 | Ui::Widget *ui; 27 | }; 28 | #endif // WIDGET_H 29 | -------------------------------------------------------------------------------- /1.EnvironmentSetup/1-1Teaser/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | } 12 | 13 | Widget::~Widget() 14 | { 15 | delete ui; 16 | } 17 | 18 | 19 | void Widget::on_submitButton_clicked() 20 | { 21 | qDebug() << "Last Name : " << ui->lastNameLineEdit->text(); 22 | qDebug() << "First Name : " << ui->firtNameLineEdit->text(); 23 | qDebug() << "Message : " << ui->messageTextEdit->toPlainText(); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-1HeapStackMemory/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "house.h" 4 | 5 | 6 | void do_stuff(){ 7 | //Stack memory 8 | /* 9 | House h1(nullptr,"First"); // Stack object 10 | h1.print_info(); 11 | */ 12 | 13 | //Heap memory 14 | House* p_h1 = new House(nullptr,"First"); 15 | p_h1->print_info(); 16 | delete p_h1; 17 | } 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | QCoreApplication a(argc, argv); 22 | do_stuff() ; 23 | 24 | qDebug() << "Done!"; 25 | 26 | return a.exec(); 27 | } 28 | -------------------------------------------------------------------------------- /2.GettingStarted/2-3QtConsoleApp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(2-3QtConsoleApp LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) 16 | 17 | add_executable(2-3QtConsoleApp 18 | main.cpp 19 | ) 20 | target_link_libraries(2-3QtConsoleApp Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/styles/style.css: -------------------------------------------------------------------------------- 1 | QPushButton[text="Submit"]{ 2 | color : white; 3 | background-color : gray; 4 | } 5 | QPushButton#okButton{ 6 | color : white; 7 | background-color : green; 8 | } 9 | QPushButton#cancelButton{ 10 | color : white; 11 | background-color : red; 12 | } 13 | 14 | QLineEdit{ 15 | padding : 1px; 16 | border : 2px solid gray; 17 | border-radius : 8px; 18 | background-color : yellow; 19 | height: 30px; 20 | } 21 | 22 | QWidget#Widget > QLabel{ 23 | font-weight : bold; 24 | font-size : 12px; 25 | } 26 | 27 | 28 | -------------------------------------------------------------------------------- /10.FilesDirectories/10-1QFileDemo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_writeButton_clicked(); 20 | 21 | void on_readButton_clicked(); 22 | 23 | void on_copyButton_clicked(); 24 | 25 | void on_selectFileButton_clicked(); 26 | 27 | private: 28 | Ui::Widget *ui; 29 | }; 30 | #endif // WIDGET_H 31 | -------------------------------------------------------------------------------- /7.Resources/7-1ResourcesDemo/resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | images/quitIcon.png 4 | images/minions.png 5 | 6 | 7 | images/copyIcon.png 8 | images/cutIcon.png 9 | images/pasteIcon.png 10 | images/redoIcon.png 11 | images/undoIcon.png 12 | 13 | 14 | images/aboutIcon.png 15 | images/aboutQtIcon.png 16 | 17 | 18 | -------------------------------------------------------------------------------- /2.GettingStarted/2-11ClassesMultipleFiles/rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "rectangle.h" 2 | 3 | //Constructor Impementations 4 | Rectangle::Rectangle(){ 5 | std::cout << "No param constructor called" << std::endl; 6 | } 7 | Rectangle::Rectangle(int w,int l){ 8 | std::cout << "Two param constructor called" << std::endl; 9 | m_width = w; 10 | m_length = l; 11 | } 12 | 13 | //Other methods 14 | void Rectangle::setWidth( int width){ 15 | m_width = width; 16 | } 17 | void Rectangle::setLength( int length){ 18 | m_length = length; 19 | } 20 | 21 | int Rectangle::get_area() const 22 | { 23 | return m_width * m_length; 24 | } 25 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-2SmartPointers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(3-2SmartPointers LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) 16 | 17 | add_executable(3-2SmartPointers 18 | main.cpp 19 | house.h 20 | house.cpp 21 | ) 22 | target_link_libraries(3-2SmartPointers Qt${QT_VERSION_MAJOR}::Core) 23 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-7QTVQFSM/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | namespace Ui { class Widget; } 10 | QT_END_NAMESPACE 11 | 12 | class Widget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | Widget(QWidget *parent = nullptr); 18 | ~Widget(); 19 | 20 | private slots: 21 | void on_readDataButton_clicked(); 22 | 23 | private: 24 | Ui::Widget *ui; 25 | QFileSystemModel * dir_model; 26 | QStandardItemModel * standard_item_tree_model; 27 | }; 28 | #endif // WIDGET_H 29 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-1HeapStackMemory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(3-1HeapStackMemory LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) 16 | 17 | add_executable(3-1HeapStackMemory 18 | main.cpp 19 | house.h 20 | house.cpp 21 | ) 22 | target_link_libraries(3-1HeapStackMemory Qt${QT_VERSION_MAJOR}::Core) 23 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-12CheckBoxesRadioButtons/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_windowsCheckBox_toggled(bool checked); 20 | 21 | void on_beerCheckBox_toggled(bool checked); 22 | 23 | void on_grabDataButton_clicked(); 24 | 25 | void on_setDataButton_clicked(); 26 | 27 | private: 28 | Ui::Widget *ui; 29 | }; 30 | #endif // WIDGET_H 31 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-9QVBoxLayout/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | /* 12 | QVBoxLayout * layout = new QVBoxLayout(); 13 | 14 | layout->addWidget(ui->oneButton); 15 | layout->addWidget(ui->twoButton); 16 | layout->addWidget(ui->threeButton); 17 | layout->addWidget(ui->fourButton); 18 | layout->addWidget(ui->fiveButton); 19 | 20 | setLayout(layout); 21 | */ 22 | 23 | } 24 | 25 | Widget::~Widget() 26 | { 27 | delete ui; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | #include 5 | 6 | QString readTextFile(QString path) 7 | { 8 | QFile file(path); 9 | 10 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) 11 | { 12 | QTextStream in(&file); 13 | return in.readAll(); 14 | } 15 | return ""; 16 | } 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | QApplication a(argc, argv); 21 | 22 | QString css = readTextFile(":/styles/style.css"); 23 | if(css.length() > 0){ 24 | a.setStyleSheet(css); 25 | } 26 | Widget w; 27 | w.show(); 28 | return a.exec(); 29 | } 30 | -------------------------------------------------------------------------------- /10.FilesDirectories/10-2QDirDemo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Widget; } 8 | QT_END_NAMESPACE 9 | 10 | class Widget : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Widget(QWidget *parent = nullptr); 16 | ~Widget(); 17 | 18 | private slots: 19 | void on_chooseDirButton_clicked(); 20 | 21 | void on_createDirButton_clicked(); 22 | 23 | void on_dirExistsButton_clicked(); 24 | 25 | void on_dirOrFileButton_clicked(); 26 | 27 | void on_folderContent_clicked(); 28 | 29 | private: 30 | Ui::Widget *ui; 31 | }; 32 | #endif // WIDGET_H 33 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-2QNetworkAccessManagerDemo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | public slots: 20 | void dataReadyToRead(); 21 | void dataReadFinished(); 22 | 23 | private: 24 | Ui::Widget *ui; 25 | QNetworkAccessManager * net_manager; 26 | QNetworkReply * net_reply; 27 | QByteArray * m_data_buffer; 28 | }; 29 | #endif // WIDGET_H 30 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-2QNetworkAccessManagerDemo/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 278 10 | 214 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /6.Dialogs/6-1QDialogDemo/infodialog.h: -------------------------------------------------------------------------------- 1 | #ifndef INFODIALOG_H 2 | #define INFODIALOG_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class InfoDialog; 8 | } 9 | 10 | class InfoDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit InfoDialog(QWidget *parent = nullptr); 16 | ~InfoDialog(); 17 | 18 | const QString &position() const; 19 | const QString &favorite_os() const; 20 | 21 | private slots: 22 | void on_okButton_clicked(); 23 | 24 | void on_cancelButton_clicked(); 25 | 26 | private: 27 | QString m_position; 28 | QString m_favorite_os; 29 | Ui::InfoDialog *ui; 30 | }; 31 | 32 | #endif // INFODIALOG_H 33 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-3QtParentChildRelationship/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(3-3QtParentChildRelationship LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) 16 | 17 | add_executable(3-3QtParentChildRelationship 18 | main.cpp 19 | house.h 20 | house.cpp 21 | ) 22 | target_link_libraries(3-3QtParentChildRelationship Qt${QT_VERSION_MAJOR}::Core) 23 | -------------------------------------------------------------------------------- /6.Dialogs/6-4QFontDialog/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | #include 5 | 6 | Widget::Widget(QWidget *parent) 7 | : QWidget(parent) 8 | , ui(new Ui::Widget) 9 | { 10 | ui->setupUi(this); 11 | } 12 | 13 | Widget::~Widget() 14 | { 15 | delete ui; 16 | } 17 | 18 | 19 | void Widget::on_chooseFontButton_clicked() 20 | { 21 | bool ok; 22 | QFont font = QFontDialog::getFont( 23 | &ok, QFont("Helvetica [Cronyx]", 10), this); 24 | if (ok) { 25 | ui->label->setFont(font); 26 | } else { 27 | qDebug() << "User didn't choose any font"; 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-3JsonClient/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | private slots: 20 | void on_fetchButton_clicked(); 21 | void dataReadyRead(); 22 | void dataReadFinished(); 23 | 24 | private: 25 | Ui::Widget *ui; 26 | QNetworkAccessManager * net_manager; 27 | QNetworkReply * net_reply; 28 | QByteArray * m_data_buffer; 29 | }; 30 | #endif // WIDGET_H 31 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/infodialog.h: -------------------------------------------------------------------------------- 1 | #ifndef INFODIALOG_H 2 | #define INFODIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | namespace Ui { 8 | class InfoDialog; 9 | } 10 | 11 | class InfoDialog : public QDialog 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | explicit InfoDialog(QWidget *parent = nullptr); 17 | ~InfoDialog(); 18 | 19 | const QString &position() const; 20 | const QString &favorite_os() const; 21 | 22 | private slots: 23 | 24 | void on_buttonBox_clicked(QAbstractButton *button); 25 | 26 | private: 27 | QString m_position; 28 | QString m_favorite_os; 29 | Ui::InfoDialog *ui; 30 | }; 31 | 32 | #endif // INFODIALOG_H 33 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-10CustomTableModel/customtablemodel.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMTABLEMODEL_H 2 | #define CUSTOMTABLEMODEL_H 3 | 4 | #include 5 | 6 | class CustomTableModel : public QAbstractTableModel 7 | { 8 | public: 9 | explicit CustomTableModel(QObject *parent = nullptr); 10 | 11 | // QAbstractItemModel interface 12 | int rowCount(const QModelIndex &parent) const; 13 | int columnCount(const QModelIndex &parent) const; 14 | QVariant data(const QModelIndex &index, int role) const; 15 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; 16 | 17 | private: 18 | QVector> table; 19 | }; 20 | 21 | #endif // CUSTOMTABLEMODEL_H 22 | -------------------------------------------------------------------------------- /2.GettingStarted/2-13GuiIntro/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 692 10 | 126 11 | 12 | 13 | 14 | MyApp 15 | 16 | 17 | 18 | 19 | 20 | Click 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /6.Dialogs/6-3QFileDialog/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 58 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | Choose 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /6.Dialogs/6-6QInputDialog/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 566 10 | 61 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | Click 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 747 10 | 75 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | Show Info 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-8QHBoxLayout/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | /* 12 | QHBoxLayout *layout = new QHBoxLayout(); 13 | 14 | layout->addWidget(ui->oneButton); 15 | layout->addWidget(ui->twoButton); 16 | layout->addWidget(ui->threeButton); 17 | layout->addWidget(ui->fourButton); 18 | layout->addWidget(ui->fiveButton); 19 | 20 | setLayout(layout);//This widget will take over the memory management 21 | //responsibilities for the layout object 22 | */ 23 | } 24 | 25 | Widget::~Widget() 26 | { 27 | delete ui; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-2QListWidgetDemo/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | Widget::~Widget() 13 | { 14 | delete ui; 15 | } 16 | 17 | 18 | void Widget::on_listItemsButton_clicked() 19 | { 20 | //qDebug() << "count : " << ui->listWidget->count(); 21 | for(size_t i{}; i < ui->listWidget->count();++i){ 22 | auto item_ptr = ui->listWidget->item(i); 23 | QVariant data = item_ptr->data(Qt::DisplayRole); 24 | qDebug() << data.toString(); 25 | } 26 | } 27 | 28 | 29 | void Widget::on_addItemButton_clicked() 30 | { 31 | ui->listWidget->addItem("Hello World"); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-4CaloryCounter/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include "person.h" 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { class Widget; } 9 | QT_END_NAMESPACE 10 | 11 | class Widget : public QWidget 12 | { 13 | Q_OBJECT 14 | 15 | public: 16 | Widget(QWidget *parent = nullptr); 17 | ~Widget(); 18 | 19 | private slots: 20 | void calculate_calories(); 21 | void weight_changed(double weight); 22 | void time_changed(double time); 23 | void speed_changed(double speed); 24 | 25 | signals : 26 | void calory_count_changed(); 27 | 28 | private: 29 | Ui::Widget *ui; 30 | Person m_person; 31 | double m_time; 32 | double m_speed; 33 | double m_calory_count; 34 | }; 35 | #endif // WIDGET_H 36 | -------------------------------------------------------------------------------- /2.GettingStarted/2-8Functions/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int add(int a ,int b){ 4 | return a + b; 5 | } 6 | 7 | float add(float a ,float b){ 8 | return a + b; 9 | } 10 | 11 | double add(double a ,double b){ 12 | return a + b; 13 | } 14 | 15 | 16 | void sayHi(){ 17 | std::cout << "Hello there" << std::endl; 18 | 19 | } 20 | 21 | int main() 22 | { 23 | float a {3.8f}; 24 | float b {7.3f}; 25 | int c {34}; 26 | 27 | auto result = add(a,b); 28 | std::cout << "result : " << result << std::endl; 29 | std::cout << "sizeof(result) : " << sizeof(result) << std::endl; 30 | //auto result1 = add(a,c); 31 | //std::cout << "result1: " << result1 << std::endl; 32 | 33 | 34 | for(int i = 0; i < 20; ++i){ 35 | sayHi(); 36 | } 37 | 38 | return 0; 39 | } 40 | 41 | 42 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-3QtParentChildRelationship/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "house.h" 5 | 6 | void do_stuff(){ 7 | 8 | //Qt Parent Child relationship 9 | //House* p_parent = new House(nullptr,"Parent"); 10 | 11 | //Can even manage the parent through smart pointers if necessary 12 | std::unique_ptr p_parent {new House(nullptr,"Parent")}; 13 | 14 | House* p_house1 = new House(p_parent.get(),"House1"); 15 | 16 | House* p_house2 = new House(p_parent.get(),"House2"); 17 | 18 | //delete p_parent; 19 | } 20 | 21 | int main(int argc, char *argv[]) 22 | { 23 | QCoreApplication a(argc, argv); 24 | qDebug() << "Starting..."; 25 | do_stuff(); 26 | qDebug() << "Ending..."; 27 | 28 | return a.exec(); 29 | } 30 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-6QTVQSIM/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 282 10 | 307 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Read Data 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | //Set stylesheet to a leaf independent component 11 | //ui->clickButton->setStyleSheet("QPushButton{background-color : yellow; color : red;}"); 12 | ui->clickButton->setStyleSheet("background-color : yellow; color : red;"); 13 | } 14 | 15 | Widget::~Widget() 16 | { 17 | delete ui; 18 | } 19 | 20 | 21 | void Widget::on_clickButton_clicked() 22 | { 23 | SomeDialog * dialog = new SomeDialog(this); 24 | 25 | //Set the stylesheet to the parent widget 26 | //dialog->setStyleSheet("QPushButton{background-color : yellow; color : red;}"); 27 | 28 | dialog->exec(); 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-5QListViewQStringListModel/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 245 10 | 230 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Show Data 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /2.GettingStarted/2-9ClassDeclaration/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | class Rectangle{ 5 | public : 6 | void set_width(int width); 7 | void set_height(int height); 8 | double get_area()const; 9 | 10 | private: 11 | double m_width; 12 | double m_height; 13 | }; 14 | 15 | //Implementations 16 | void Rectangle::set_width(int width){ 17 | m_width = width; 18 | } 19 | void Rectangle::set_height(int height){ 20 | m_height = height; 21 | } 22 | double Rectangle::get_area()const{ 23 | return m_width * m_height; 24 | } 25 | 26 | int main() 27 | { 28 | Rectangle r; 29 | r.set_width(10.0); 30 | r.set_height(30.0); 31 | std::cout << "area : " << r.get_area() << std::endl; 32 | 33 | //Can't access private data of the class from the outside 34 | //std::cout << "width : " << r.m_width << std::endl; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-2DifferentConnectionSyntaxes/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | //String notation 10 | /* 11 | connect(ui->myButton,SIGNAL(clicked()),this,SLOT(change_text())); 12 | */ 13 | 14 | //Functor Notation : Regular Slots 15 | /* 16 | connect(ui->myButton,&QPushButton::clicked,this,&Widget::change_text); 17 | */ 18 | 19 | //Functor Notation : Lambdas 20 | connect(ui->myButton,&QPushButton::clicked,[=](){ 21 | ui->label->setText("Some other text from lambda"); 22 | }); 23 | 24 | } 25 | 26 | Widget::~Widget() 27 | { 28 | delete ui; 29 | } 30 | 31 | void Widget::change_text() 32 | { 33 | ui->label->setText("Some other text"); 34 | } 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class MainWindow; } 8 | QT_END_NAMESPACE 9 | 10 | class MainWindow : public QMainWindow 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | MainWindow(QWidget *parent = nullptr); 16 | ~MainWindow(); 17 | 18 | private slots: 19 | void on_actionQuit_triggered(); 20 | 21 | void on_actionAbout_triggered(); 22 | 23 | void on_actionAbout_Qt_triggered(); 24 | 25 | void on_actionCopy_triggered(); 26 | 27 | void on_actionCut_triggered(); 28 | 29 | void on_actionPaste_triggered(); 30 | 31 | void on_actionUndo_triggered(); 32 | 33 | void on_actionRedo_triggered(); 34 | 35 | void quitApp(); 36 | 37 | private: 38 | Ui::MainWindow *ui; 39 | }; 40 | #endif // MAINWINDOW_H 41 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-11EditableCustomModel/customtablemodel.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMTABLEMODEL_H 2 | #define CUSTOMTABLEMODEL_H 3 | 4 | #include 5 | 6 | class CustomTableModel : public QAbstractTableModel 7 | { 8 | public: 9 | explicit CustomTableModel(QObject *parent = nullptr); 10 | 11 | // QAbstractItemModel interface 12 | int rowCount(const QModelIndex &parent) const; 13 | int columnCount(const QModelIndex &parent) const; 14 | QVariant data(const QModelIndex &index, int role) const; 15 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; 16 | 17 | //Modifications 18 | bool setData(const QModelIndex &index, const QVariant &value, int role); 19 | Qt::ItemFlags flags(const QModelIndex &index) const; 20 | 21 | private: 22 | QVector> table; 23 | 24 | 25 | }; 26 | 27 | #endif // CUSTOMTABLEMODEL_H 28 | -------------------------------------------------------------------------------- /3.MemoryManagement/3-2SmartPointers/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "house.h" 5 | 6 | void do_stuff(){ 7 | //Stack memory 8 | /* 9 | House h1(nullptr,"First"); 10 | h1.print_info(); 11 | */ 12 | 13 | 14 | //Heap memory 15 | /* 16 | House* p_h1 = new House(nullptr,"First"); 17 | p_h1->print_info(); 18 | delete p_h1; 19 | */ 20 | 21 | //Unique ptr 22 | /* 23 | std::unique_ptr up_house_1 {new House(nullptr,"Second")}; 24 | up_house_1->print_info(); 25 | */ 26 | 27 | //Shared ptr 28 | std::shared_ptr shrd_ptr_1 {new House(nullptr,"Third")}; 29 | shrd_ptr_1->print_info(); 30 | 31 | } 32 | 33 | int main(int argc, char *argv[]) 34 | { 35 | QCoreApplication a(argc, argv); 36 | 37 | qDebug() << "Starting..."; 38 | do_stuff(); 39 | qDebug() << "Ending..."; 40 | 41 | return a.exec(); 42 | } 43 | -------------------------------------------------------------------------------- /6.Dialogs/6-1QDialogDemo/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 160 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | Provide Info 21 | 22 | 23 | 24 | 25 | 26 | 27 | TextLabel 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-2DifferentConnectionSyntaxes/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 524 10 | 83 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | Click 21 | 22 | 23 | 24 | 25 | 26 | 27 | Get out of here 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/somedialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SomeDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 87 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | Inside Dialog 21 | 22 | 23 | 24 | 25 | 26 | 27 | PushButton 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-4QPushButton/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | { 8 | //Clicked signal 9 | QFont button_font("Times", 20, QFont::Bold); 10 | QPushButton * button = new QPushButton("Button1",this); 11 | button->setMinimumSize(200,100); 12 | button->setFont(button_font); 13 | connect(button,&QPushButton::clicked,[=](){ 14 | qDebug() << "Button clicked"; 15 | }); 16 | 17 | 18 | QPushButton * button2 = new QPushButton("Button2",this); 19 | button2->setMinimumSize(200,100); 20 | button2->move(205,0); 21 | button2->setFont(button_font); 22 | connect(button2,&QPushButton::pressed,[=](){ 23 | qDebug() << "Button pressed"; 24 | }); 25 | 26 | connect(button2,&QPushButton::released,[=](){ 27 | qDebug() << "Button released"; 28 | }); 29 | 30 | 31 | 32 | } 33 | 34 | Widget::~Widget() 35 | { 36 | } 37 | 38 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-4QTreeWidget/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 376 10 | 366 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 1 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | List Items 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-11QGridLayout/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | //QGridLayout * layout = new QGridLayout(this); 12 | 13 | QGridLayout * layout = new QGridLayout(); 14 | 15 | //First row 16 | layout->addWidget(ui->button1,0,0); 17 | layout->addWidget(ui->button2,0,1); 18 | layout->addWidget(ui->button3,0,2,2,1); // Row span : 2 19 | // Column span : 1 20 | //Second row 21 | layout->addWidget(ui->button4,1,0); 22 | layout->addWidget(ui->button5,1,1); 23 | 24 | //Third row 25 | layout->addWidget(ui->button7,2,0,1,2); // Row span : 1 26 | // Column span : 2 27 | layout->addWidget(ui->button9,2,2); 28 | 29 | setLayout(layout); 30 | } 31 | 32 | Widget::~Widget() 33 | { 34 | delete ui; 35 | } 36 | 37 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-7QTVQFSM/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 384 10 | 285 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Read data 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-13QList/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QCoreApplication a(argc, argv); 7 | 8 | //Declare the list 9 | QList stringList; 10 | 11 | //Put data in the list 12 | stringList << " I am " << " lovin " << " Qt";// [ "I am", " loving ", " Qt"] 13 | stringList.append(" a "); 14 | stringList.append( " lot !"); 15 | 16 | //Get the data from the list 17 | qDebug() << "The first element is " << stringList[0]; 18 | qDebug() << "The second element is " << stringList[1]; 19 | qDebug() << "The third element is " << stringList[2]; 20 | //Get the number of elements 21 | qDebug() << "The number of elements in my list is : " << stringList.count(); 22 | 23 | //Loop through the elements 24 | for( int i = 0 ; i < stringList.count() ; i++) 25 | { 26 | qDebug() << "The element at index "<< QString::number(i) 27 | << " is " << stringList.at(i); 28 | } 29 | 30 | 31 | return a.exec(); 32 | } 33 | -------------------------------------------------------------------------------- /6.Dialogs/6-4QFontDialog/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 369 10 | 99 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 12 22 | 23 | 24 | 25 | Some Text 26 | 27 | 28 | 29 | 30 | 31 | 32 | Choose Font 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 405 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 22 | true 23 | 24 | 25 | 26 | Minion 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/infodialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | InfoDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 667 10 | 78 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | Do you want to continue? 21 | 22 | 23 | 24 | 25 | 26 | 27 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Open|QDialogButtonBox::Save|QDialogButtonBox::SaveAll 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /1.EnvironmentSetup/1-1Teaser/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-7QTVQFSM/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-10SizePoliciesStretches/.gitignore: -------------------------------------------------------------------------------- 1 | # This file is used to ignore files which are generated 2 | # ---------------------------------------------------------------------------- 3 | 4 | *~ 5 | *.autosave 6 | *.a 7 | *.core 8 | *.moc 9 | *.o 10 | *.obj 11 | *.orig 12 | *.rej 13 | *.so 14 | *.so.* 15 | *_pch.h.cpp 16 | *_resource.rc 17 | *.qm 18 | .#* 19 | *.*# 20 | core 21 | !core/ 22 | tags 23 | .DS_Store 24 | .directory 25 | *.debug 26 | Makefile* 27 | *.prl 28 | *.app 29 | moc_*.cpp 30 | ui_*.h 31 | qrc_*.cpp 32 | Thumbs.db 33 | *.res 34 | *.rc 35 | /.qmake.cache 36 | /.qmake.stash 37 | 38 | # qtcreator generated files 39 | *.pro.user* 40 | 41 | # xemacs temporary files 42 | *.flc 43 | 44 | # Vim temporary files 45 | .*.swp 46 | 47 | # Visual Studio generated files 48 | *.ib_pdb_index 49 | *.idb 50 | *.ilk 51 | *.pdb 52 | *.sln 53 | *.suo 54 | *.vcproj 55 | *vcproj.*.*.user 56 | *.ncb 57 | *.sdf 58 | *.opensdf 59 | *.vcxproj 60 | *vcxproj.* 61 | 62 | # MinGW generated files 63 | *.Debug 64 | *.Release 65 | 66 | # Python byte code 67 | *.pyc 68 | 69 | # Binaries 70 | # -------- 71 | *.dll 72 | *.exe 73 | 74 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-5QListViewQStringListModel/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | model = new QStringListModel(this); 11 | 12 | QStringList list; 13 | list << "Cow" << "Rooster" << "Lion" << "Hyena" << "Buffalo"; 14 | 15 | model->setStringList(list); 16 | 17 | ui->listView->setModel(model); 18 | } 19 | 20 | Widget::~Widget() 21 | { 22 | delete ui; 23 | } 24 | 25 | 26 | void Widget::on_showData_clicked() 27 | { 28 | //Reading data with high level API 29 | /* 30 | QStringList list = model->stringList(); 31 | qDebug() << "The current data is :" << list; 32 | */ 33 | 34 | //Reading data with low level QAbstractItemModel API 35 | for(size_t i{}; i < model->rowCount(QModelIndex());++i){ 36 | auto index = model->index(i,0,QModelIndex()); 37 | auto data = index.data(Qt::DisplayRole); 38 | //auto data = model->data(index); 39 | qDebug() << data.toString(); 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /9.Settings/9-2QSettingsDemo/widget.h: -------------------------------------------------------------------------------- 1 | #ifndef WIDGET_H 2 | #define WIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | namespace Ui { class Widget; } 10 | QT_END_NAMESPACE 11 | 12 | class Widget : public QWidget 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | Widget(QWidget *parent = nullptr); 18 | ~Widget(); 19 | 20 | private slots: 21 | void on_buttonOne_clicked(); 22 | 23 | void on_buttonTwo_clicked(); 24 | 25 | void on_buttonThree_clicked(); 26 | 27 | void on_buttonFour_clicked(); 28 | 29 | void on_buttonFive_clicked(); 30 | 31 | void on_buttonSix_clicked(); 32 | 33 | void on_buttonSeven_clicked(); 34 | 35 | void on_buttonEight_clicked(); 36 | 37 | void on_buttonNine_clicked(); 38 | 39 | void on_saveButton_clicked(); 40 | 41 | void on_loadButton_clicked(); 42 | 43 | private: 44 | Ui::Widget *ui; 45 | QList m_color_list; 46 | 47 | void save_color( QString key, QColor color); 48 | QColor load_color(QString key); 49 | 50 | void set_loaded_color( QString key, int index, QPushButton * button); 51 | }; 52 | #endif // WIDGET_H 53 | -------------------------------------------------------------------------------- /6.Dialogs/6-6QInputDialog/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | Widget::~Widget() 13 | { 14 | delete ui; 15 | } 16 | 17 | 18 | void Widget::on_clickButton_clicked() 19 | { 20 | 21 | //QDoubleSpinBox Mode 22 | /* 23 | bool ok; 24 | double d = QInputDialog::getDouble(this, tr("QInputDialog::getDouble()"), 25 | tr("Amount:"), 37.56, -10000, 10000, 2, &ok); 26 | if (ok) 27 | { 28 | qDebug() << "Your double value is " << QString::number(d); 29 | } 30 | */ 31 | 32 | //QComboBox Mode 33 | QStringList items; 34 | items << tr("Spring") << tr("Summer") << tr("Fall") << tr("Winter"); 35 | bool ok; 36 | QString item = QInputDialog::getItem(this, tr("QInputDialog::getItem()"), 37 | tr("Season:"), items, 0, false, &ok); 38 | if (ok && !item.isEmpty()) 39 | { 40 | qDebug() << "Your chosen item is "<< item; 41 | } 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-6QTVQSIM/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | 10 | model = new QStandardItemModel(4, 4); 11 | for (int row = 0; row < model->rowCount(); ++row) { 12 | for (int column = 0; column < model->columnCount(); ++column) { 13 | QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); 14 | model->setItem(row, column, item); 15 | } 16 | } 17 | 18 | ui->tableView->setModel(model); 19 | 20 | } 21 | 22 | Widget::~Widget() 23 | { 24 | delete ui; 25 | } 26 | 27 | 28 | void Widget::on_readData_clicked() 29 | { 30 | for (int row = 0; row < model->rowCount(); ++row) { 31 | for (int column = 0; column < model->columnCount(); ++column) { 32 | auto index = model->index(row,column,QModelIndex()); 33 | //auto data = index.data(Qt::DisplayRole); 34 | auto data = model->data(index,Qt::DisplayRole); 35 | qDebug() << data.toString(); 36 | } 37 | qDebug() << "------"; 38 | 39 | } 40 | 41 | } 42 | 43 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-3WidgetsSignalsSlots/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 661 10 | 124 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 1 21 | 22 | 23 | 100 24 | 25 | 26 | Qt::Horizontal 27 | 28 | 29 | 30 | 31 | 32 | 33 | 1 34 | 35 | 36 | 1 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-15QTabWidget/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | //Declare the widget 12 | QWidget * widget = new QWidget(this); 13 | 14 | //Declare the layout for the widget 15 | QVBoxLayout * layout = new QVBoxLayout(); 16 | 17 | layout->addWidget(new QPushButton("Button1",this)); 18 | layout->addWidget(new QPushButton("Button2",this)); 19 | layout->addWidget(new QPushButton("Button3",this)); 20 | QPushButton * button4 = new QPushButton("Button4",this); 21 | connect(button4,&QPushButton::clicked,[=](){ 22 | qDebug() << "Button4 from custom tab clicked"; 23 | }); 24 | layout->addWidget(button4); 25 | layout->addSpacerItem(new QSpacerItem(100,200)); 26 | 27 | //Set the layout to the widget 28 | widget->setLayout(layout); 29 | 30 | ui->tabWidget->insertTab(0,widget,"My Custom Tab"); 31 | } 32 | 33 | Widget::~Widget() 34 | { 35 | delete ui; 36 | } 37 | 38 | 39 | void Widget::on_pushButton_3_clicked() 40 | { 41 | qDebug() << "Clicked on the button in the tab"; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-2QMainWindow/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | MainWindow::MainWindow(QWidget *parent) 10 | : QMainWindow{parent} 11 | { 12 | //Add central widget 13 | QPushButton * button = new QPushButton("Hello",this); 14 | setCentralWidget(button); 15 | 16 | 17 | //Declare Quit Action 18 | quitAction = new QAction("Quit"); // This memory is not managed by the window 19 | // You have to release it yourself 20 | connect(quitAction,&QAction::triggered,[=](){ 21 | QApplication::quit(); 22 | }); 23 | 24 | //Add menus 25 | QMenu * fileMenu = menuBar()->addMenu("File"); 26 | fileMenu->addAction(quitAction); 27 | menuBar()->addMenu("Edit"); 28 | menuBar()->addMenu("Window"); 29 | menuBar()->addMenu("Settings"); 30 | menuBar()->addMenu("Help"); 31 | 32 | //Add status bar message 33 | statusBar()->showMessage("Uploading file ...",0); 34 | statusBar()->clearMessage(); 35 | 36 | } 37 | 38 | 39 | QSize MainWindow::sizeHint() const 40 | { 41 | return QSize(800,500); 42 | } 43 | -------------------------------------------------------------------------------- /2.GettingStarted/2-7GuessNumber/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include /* srand, rand */ 3 | #include 4 | 5 | int main() 6 | { 7 | std::srand(std::time(nullptr)); // use current time as seed for random generator 8 | 9 | int random_number = std::rand(); 10 | // std::cout << "number : " << random_number << std::endl; 11 | // std::cout << "RAND_MAX : " << RAND_MAX << std::endl; 12 | 13 | //Make sure the number is between 1 and 10 14 | 15 | int secret_number = random_number % 10 +1; 16 | // std::cout << "secret_number : " << secret_number << std::endl; 17 | 18 | int guess_number; 19 | 20 | //Ask the user to guess 21 | std::cout << "Guess my number ( 1-10 ) :"; 22 | do 23 | { 24 | std::cin >> guess_number; 25 | if( secret_number < guess_number) 26 | { 27 | std::cout << "The number is lower than that" < guess_number) 31 | { 32 | std::cout << "The number is higher than that" < 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | //String notation 12 | /* 13 | connect(ui->horizontalSlider,SIGNAL(valueChanged(int)), 14 | ui->progressBar,SLOT(setValue(int))); 15 | connect(ui->horizontalSlider,SIGNAL(valueChanged(int)), 16 | this,SLOT(respond(int))); 17 | */ 18 | 19 | //Functor Notation : Regular Slots 20 | /* 21 | connect(ui->horizontalSlider,&QSlider::valueChanged, 22 | ui->progressBar,&QProgressBar::setValue); 23 | connect(ui->horizontalSlider,&QSlider::valueChanged, 24 | this,&Widget::respond); 25 | */ 26 | 27 | //Functor Notation : Lambas 28 | connect(ui->horizontalSlider,&QSlider::valueChanged, 29 | [=] (){ 30 | ui->progressBar->setValue(ui->horizontalSlider->value()); 31 | respond(ui->horizontalSlider->value()); 32 | }); 33 | 34 | 35 | } 36 | 37 | Widget::~Widget() 38 | { 39 | delete ui; 40 | } 41 | 42 | void Widget::respond(int value) 43 | { 44 | qDebug() << "value : " << value; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /8.Styling/8-1QPalette/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | ui->label->setAutoFillBackground(true); 12 | 13 | //Retrieve the palette for the label 14 | QPalette palette = ui->label->palette(); 15 | 16 | //Modify the palette with our changes 17 | palette.setColor(QPalette::Window,Qt::blue); 18 | palette.setColor(QPalette::WindowText,Qt::red); 19 | 20 | //Reset the palette to the widget 21 | ui->label->setPalette(palette); 22 | } 23 | 24 | Widget::~Widget() 25 | { 26 | delete ui; 27 | } 28 | 29 | 30 | void Widget::on_activeButton_clicked() 31 | { 32 | QPalette::ColorGroup activeButtonColorGroup = ui->activeButton->palette().currentColorGroup(); 33 | QPalette::ColorGroup disabledButtonColorGroup = ui->disabledButton->palette().currentColorGroup(); 34 | 35 | qDebug() << " Active button color group : " << activeButtonColorGroup; 36 | qDebug() << " Disabled button color group : " <setupUi(this); 9 | } 10 | 11 | InfoDialog::~InfoDialog() 12 | { 13 | delete ui; 14 | } 15 | 16 | void InfoDialog::on_okButton_clicked() 17 | { 18 | QString user_position = ui->positionLineEdit->text(); 19 | 20 | if(!user_position.isEmpty()){ 21 | m_position = user_position; 22 | 23 | if(ui->windowsRadioButton->isChecked()){ 24 | m_favorite_os = "Windows"; 25 | } 26 | if(ui->macRadioButton->isChecked()){ 27 | m_favorite_os = "Mac"; 28 | } 29 | if(ui->linuxRadioButton->isChecked()) 30 | { 31 | m_favorite_os = "Linux"; 32 | } 33 | 34 | //Accept 35 | accept(); 36 | 37 | }else{ 38 | reject(); 39 | } 40 | 41 | } 42 | 43 | 44 | void InfoDialog::on_cancelButton_clicked() 45 | { 46 | //Reject the dialog 47 | reject(); 48 | } 49 | 50 | const QString &InfoDialog::position() const 51 | { 52 | return m_position; 53 | } 54 | 55 | const QString &InfoDialog::favorite_os() const 56 | { 57 | return m_favorite_os; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-14QListWidget/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | 10 | ui->listWidget->setSelectionMode(QAbstractItemView::MultiSelection); 11 | 12 | ui->listWidget->addItem("Item1"); 13 | ui->listWidget->addItem("Item2"); 14 | QStringList listData; 15 | listData << "Item3" << "Item4" << "Item5"; 16 | ui->listWidget->addItems(listData); 17 | } 18 | 19 | Widget::~Widget() 20 | { 21 | delete ui; 22 | } 23 | 24 | 25 | void Widget::on_addItemButton_clicked() 26 | { 27 | ui->listWidget->addItem("Another item"); 28 | } 29 | 30 | 31 | void Widget::on_removeItemButton_clicked() 32 | { 33 | //Delete item : use takeItem 34 | ui->listWidget->takeItem(ui->listWidget->currentRow()); 35 | } 36 | 37 | 38 | void Widget::on_selectedItemsButton_clicked() 39 | { 40 | // Get the list of selected items 41 | QList list = ui->listWidget->selectedItems(); 42 | 43 | for( int i = 0; i < list.count(); i++) 44 | { 45 | qDebug() << "Selected item : " << list.at(i)->text() << " , row number id : "<< 46 | ui->listWidget->row(list.at(i)); 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-3JsonClient/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 339 10 | 277 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 24 | 25 | 26 | 27 | POST Fetchr 28 | 29 | 30 | 31 | 32 | 33 | 34 | Fetch 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-2QListWidgetDemo/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 271 10 | 270 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | One 22 | 23 | 24 | 25 | 26 | Two 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | List items 35 | 36 | 37 | 38 | 39 | 40 | 41 | Add Item 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /12.QtNetworkOfferings/12-2QNetworkAccessManagerDemo/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | //Initialization 11 | net_manager = new QNetworkAccessManager(this); 12 | net_reply = nullptr; 13 | m_data_buffer = new QByteArray(); 14 | 15 | //Send out the request 16 | QNetworkRequest request; 17 | //request.setUrl(QUrl("https://www.qt.io")); 18 | request.setUrl(QUrl("https://www.github.com")); 19 | 20 | net_reply = net_manager->get(request); 21 | 22 | connect(net_reply,&QIODevice::readyRead,this,&Widget::dataReadyToRead); 23 | connect(net_reply,&QNetworkReply::finished,this,&Widget::dataReadFinished); 24 | } 25 | 26 | Widget::~Widget() 27 | { 28 | delete m_data_buffer; 29 | delete ui; 30 | } 31 | 32 | void Widget::dataReadyToRead() 33 | { 34 | qDebug()<< "Some data available"; 35 | m_data_buffer->append(net_reply->readAll()); 36 | } 37 | 38 | void Widget::dataReadFinished() 39 | { 40 | if( net_reply->error()) 41 | { 42 | qDebug() << " Error : " << QString(*m_data_buffer) ; 43 | }else 44 | { 45 | ui->textEdit->setPlainText(QString(*m_data_buffer)); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /8.Styling/8-1QPalette/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 740 10 | 80 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Active 23 | 24 | 25 | 26 | 27 | 28 | 29 | false 30 | 31 | 32 | Disabled 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | Some Text 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /6.Dialogs/6-2QDialogButtonBox/infodialog.cpp: -------------------------------------------------------------------------------- 1 | #include "infodialog.h" 2 | #include "ui_infodialog.h" 3 | 4 | InfoDialog::InfoDialog(QWidget *parent) : 5 | QDialog(parent), 6 | ui(new Ui::InfoDialog) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | InfoDialog::~InfoDialog() 12 | { 13 | delete ui; 14 | } 15 | 16 | 17 | const QString &InfoDialog::position() const 18 | { 19 | return m_position; 20 | } 21 | 22 | const QString &InfoDialog::favorite_os() const 23 | { 24 | return m_favorite_os; 25 | } 26 | 27 | 28 | void InfoDialog::on_buttonBox_clicked(QAbstractButton *button) 29 | { 30 | QDialogButtonBox::StandardButton stdButton = ui->buttonBox->standardButton(button); 31 | 32 | if( stdButton == QDialogButtonBox::Ok) 33 | { 34 | accept(); 35 | qDebug() << "OK button Clicked"; 36 | } 37 | if( stdButton == QDialogButtonBox::Save) 38 | { 39 | qDebug() << "Save button Clicked"; 40 | } 41 | 42 | if( stdButton == QDialogButtonBox::SaveAll) 43 | { 44 | qDebug() << "SaveAll button Clicked"; 45 | } 46 | if( stdButton == QDialogButtonBox::Open) 47 | { 48 | qDebug() << "Open button Clicked"; 49 | } 50 | 51 | if( stdButton == QDialogButtonBox::Cancel) 52 | { 53 | reject(); 54 | qDebug() << "Cancel button Clicked"; 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-16QComboBox/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | //Add planets to the combobox 12 | ui->comboBox->addItem("Earth"); 13 | ui->comboBox->addItem("Venus"); 14 | ui->comboBox->addItem("Mars"); 15 | ui->comboBox->addItem("Pluton"); 16 | ui->comboBox->addItem("Saturn"); 17 | 18 | ui->comboBox->setEditable(true); 19 | } 20 | 21 | Widget::~Widget() 22 | { 23 | delete ui; 24 | } 25 | 26 | 27 | void Widget::on_captureButton_clicked() 28 | { 29 | qDebug() << "The currently selectd item in the combo is : " << 30 | ui->comboBox->currentText() << 31 | " and the index is :" << QString::number(ui->comboBox->currentIndex()); 32 | } 33 | 34 | 35 | void Widget::on_setButton_clicked() 36 | { 37 | ui->comboBox->setCurrentIndex(3); 38 | } 39 | 40 | 41 | void Widget::on_listValuesButton_clicked() 42 | { 43 | qDebug() << "The combo box currently has " << 44 | QString::number(ui->comboBox->count()) << 45 | " items. They are :"; 46 | for( int i =0; i < ui->comboBox->count() ; i++) 47 | { 48 | qDebug() << "Index " << QString::number(i) << " : " << ui->comboBox->itemText(i); 49 | } 50 | } 51 | 52 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-16QComboBox/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 550 10 | 125 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Capture Current Value 26 | 27 | 28 | 29 | 30 | 31 | 32 | Set Current Value 33 | 34 | 35 | 36 | 37 | 38 | 39 | List All Values 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-12CheckBoxesRadioButtons/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | 11 | QButtonGroup * group = new QButtonGroup(this); 12 | group->addButton(ui->windowsCheckBox); 13 | group->addButton(ui->macCheckBox); 14 | group->addButton(ui->linuxCheckBox); 15 | group->setExclusive(true); 16 | } 17 | 18 | Widget::~Widget() 19 | { 20 | delete ui; 21 | } 22 | 23 | 24 | void Widget::on_windowsCheckBox_toggled(bool checked) 25 | { 26 | if( checked) 27 | { 28 | qDebug() << "Windows Checkbox is checked"; 29 | }else 30 | { 31 | qDebug() << "Windows Checkbox is unchecked"; 32 | } 33 | } 34 | 35 | 36 | void Widget::on_beerCheckBox_toggled(bool checked) 37 | { 38 | if( checked) 39 | { 40 | qDebug() << "Beer Checkbox is checked"; 41 | }else 42 | { 43 | qDebug() << "Beer Checkbox is unchecked"; 44 | } 45 | } 46 | 47 | 48 | void Widget::on_grabDataButton_clicked() 49 | { 50 | if(ui->beerCheckBox->isChecked()){ 51 | qDebug() << "Beer Checkbox is checked"; 52 | }else{ 53 | qDebug() << "Beer Checkbox is unchecked"; 54 | } 55 | } 56 | 57 | 58 | void Widget::on_setDataButton_clicked() 59 | { 60 | ui->beerCheckBox->setChecked(true); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-8QHBoxLayout/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 790 10 | 58 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | One 21 | 22 | 23 | 24 | 25 | 26 | 27 | Two 28 | 29 | 30 | 31 | 32 | 33 | 34 | Three 35 | 36 | 37 | 38 | 39 | 40 | 41 | Four 42 | 43 | 44 | 45 | 46 | 47 | 48 | Five 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-9QVBoxLayout/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 617 10 | 195 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | One 21 | 22 | 23 | 24 | 25 | 26 | 27 | Two 28 | 29 | 30 | 31 | 32 | 33 | 34 | Three 35 | 36 | 37 | 38 | 39 | 40 | 41 | Four 42 | 43 | 44 | 45 | 46 | 47 | 48 | Five 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-17MenusToolbarsActions/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "./ui_mainwindow.h" 3 | #include 4 | #include 5 | #include 6 | 7 | MainWindow::MainWindow(QWidget *parent) 8 | : QMainWindow(parent) 9 | , ui(new Ui::MainWindow) 10 | { 11 | ui->setupUi(this); 12 | } 13 | 14 | MainWindow::~MainWindow() 15 | { 16 | delete ui; 17 | } 18 | 19 | 20 | void MainWindow::on_actionQuit_triggered() 21 | { 22 | statusBar()->showMessage("App will be killed in 5 seconds..."); 23 | QTimer::singleShot(5000, this, &MainWindow::quitApp); 24 | } 25 | 26 | 27 | void MainWindow::on_actionAbout_triggered() 28 | { 29 | QMessageBox::about(this,"Message", 30 | "This is demo app to show how to use menus, toolbars and actions in Qt"); 31 | } 32 | 33 | 34 | void MainWindow::on_actionAbout_Qt_triggered() 35 | { 36 | QApplication::aboutQt(); 37 | } 38 | 39 | 40 | void MainWindow::on_actionCopy_triggered() 41 | { 42 | ui->textEdit->copy(); 43 | } 44 | 45 | 46 | void MainWindow::on_actionCut_triggered() 47 | { 48 | ui->textEdit->cut(); 49 | } 50 | 51 | 52 | void MainWindow::on_actionPaste_triggered() 53 | { 54 | ui->textEdit->paste(); 55 | } 56 | 57 | 58 | void MainWindow::on_actionUndo_triggered() 59 | { 60 | ui->textEdit->undo(); 61 | } 62 | 63 | 64 | void MainWindow::on_actionRedo_triggered() 65 | { 66 | ui->textEdit->redo(); 67 | } 68 | 69 | void MainWindow::quitApp() 70 | { 71 | QApplication::quit(); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /2.GettingStarted/2-10ClassConstructors/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Rectangle { 4 | 5 | public: 6 | //Constructors 7 | Rectangle(); 8 | Rectangle(int w,int l); 9 | 10 | void setWidth( int width); 11 | void setLength( int length); 12 | int get_area()const; 13 | 14 | private: 15 | int m_width; 16 | int m_length; 17 | }; 18 | 19 | 20 | //Constructor Impementations 21 | Rectangle::Rectangle(){ 22 | std::cout << "No param constructor called" << std::endl; 23 | } 24 | Rectangle::Rectangle(int w,int l){ 25 | std::cout << "Two param constructor called" << std::endl; 26 | m_width = w; 27 | m_length = l; 28 | } 29 | 30 | //Other methods 31 | void Rectangle::setWidth( int width){ 32 | m_width = width; 33 | } 34 | void Rectangle::setLength( int length){ 35 | m_length = length; 36 | } 37 | 38 | int Rectangle::get_area() const 39 | { 40 | return m_width * m_length; 41 | } 42 | 43 | //Box class 44 | class Box 45 | { 46 | public: 47 | Box(int w, int l, int h):m_r(w,l),m_height(h) // Initializer list 48 | { 49 | std::cout << "Para Constructor Called" << std::endl; 50 | } 51 | 52 | int get_volume() 53 | { 54 | return m_r.get_area() * m_height; 55 | } 56 | 57 | private: 58 | Rectangle m_r; 59 | int m_height; 60 | }; 61 | 62 | 63 | 64 | int main() 65 | { 66 | Rectangle r(10,20); 67 | std::cout << "area : " << r.get_area() << std::endl; 68 | 69 | Box b(10,20,30); 70 | std::cout << "volume : " << b.get_volume() << std::endl; 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-3QTableWidget/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | } 10 | 11 | Widget::~Widget() 12 | { 13 | delete ui; 14 | } 15 | 16 | 17 | void Widget::on_listItemsButton_clicked() 18 | { 19 | for(size_t i{}; i < ui->tableWidget->rowCount();++i){ 20 | for(size_t j{}; j < ui->tableWidget->columnCount(); ++j){ 21 | 22 | //Attention : If you call item() on a pair of indexes where no item 23 | // has bee set, you get nullptr. Hence the if check below 24 | // See doc for QTableWidget::item() 25 | auto item_ptr = ui->tableWidget->item(i,j); 26 | if(item_ptr){ 27 | QVariant data = item_ptr->data(Qt::DisplayRole); 28 | qDebug() << data.toString(); 29 | }else{ 30 | qDebug() << "no data"; 31 | } 32 | } 33 | } 34 | 35 | } 36 | 37 | 38 | void Widget::on_setItemButton_clicked() 39 | { 40 | //Expand the tablewidget to create a new row/column 41 | ui->tableWidget->insertRow(ui->tableWidget->rowCount()); 42 | ui->tableWidget->insertColumn(ui->tableWidget->columnCount()); 43 | 44 | //Add the item in the tableWidget 45 | QTableWidgetItem *newItem = new QTableWidgetItem("Hello"); 46 | ui->tableWidget->setItem(ui->tableWidget->rowCount()-1, 47 | ui->tableWidget->columnCount()-1, newItem); 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /6.Dialogs/6-1QDialogDemo/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include "infodialog.h" 4 | 5 | Widget::Widget(QWidget *parent) 6 | : QWidget(parent) 7 | , ui(new Ui::Widget) 8 | { 9 | ui->setupUi(this); 10 | } 11 | 12 | Widget::~Widget() 13 | { 14 | delete ui; 15 | } 16 | 17 | 18 | void Widget::on_provideInfoButton_clicked() 19 | { 20 | InfoDialog * dialog = new InfoDialog(this); 21 | 22 | //Show the dialog modal 23 | /* 24 | auto ret = dialog->exec(); 25 | 26 | if(ret == QDialog::Accepted){ 27 | 28 | QString position = dialog->position(); 29 | QString os = dialog->favorite_os(); 30 | 31 | qDebug() << "Dialog accepted ,position is : " << position 32 | << " and favorite os is : " << os; 33 | ui->infoLabel->setText("Your position is : " + position 34 | + " and your favorite os is : " + os); 35 | }else{ 36 | ui->infoLabel->setText("Dialog rejected"); 37 | } 38 | */ 39 | 40 | 41 | //Non modal 42 | connect(dialog,&InfoDialog::accepted,[=](){ 43 | QString position = dialog->position(); 44 | QString os = dialog->favorite_os(); 45 | 46 | qDebug() << "Dialog accepted ,position is : " << position << " and favorite os is : " << os; 47 | ui->infoLabel->setText("Your position is : " + position + " and your favorite os is : " + os); 48 | }); 49 | 50 | connect(dialog,&InfoDialog::rejected,[=](){ 51 | ui->infoLabel->setText("Dialog rejected"); 52 | }); 53 | 54 | dialog->show(); 55 | dialog->raise();//Put it to the top 56 | dialog->activateWindow();// Give the dialog focus 57 | } 58 | 59 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-14QListWidget/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 265 10 | 522 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Add Item 26 | 27 | 28 | 29 | 30 | 31 | 32 | Remove Item 33 | 34 | 35 | 36 | 37 | 38 | 39 | Selected Items 40 | 41 | 42 | 43 | 44 | 45 | 46 | Qt::Vertical 47 | 48 | 49 | 50 | 20 51 | 238 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/suredialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SureDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 463 10 | 115 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 22 | 23 | 24 | 25 | Are you sure? 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | Qt::Horizontal 35 | 36 | 37 | 38 | 40 39 | 20 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | OK 48 | 49 | 50 | 51 | 52 | 53 | 54 | Cancel 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /6.Dialogs/6-5QColorDialog/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | #include 4 | #include 5 | 6 | Widget::Widget(QWidget *parent) 7 | : QWidget(parent) 8 | , ui(new Ui::Widget) 9 | { 10 | ui->setupUi(this); 11 | ui->label->setAutoFillBackground(true); 12 | } 13 | 14 | Widget::~Widget() 15 | { 16 | delete ui; 17 | } 18 | 19 | 20 | void Widget::on_textColorButton_clicked() 21 | { 22 | QPalette palette = ui->label->palette(); 23 | QColor color = palette.color(QPalette::WindowText); 24 | QColor chosenColor = QColorDialog::getColor(color,this,"Choose text color"); 25 | 26 | if(chosenColor.isValid()) 27 | { 28 | palette.setColor(QPalette::WindowText,chosenColor); 29 | ui->label->setPalette(palette); 30 | qDebug() << "User chose a valid color"; 31 | }else 32 | { 33 | qDebug() << "User chose a invalid color"; 34 | } 35 | 36 | } 37 | 38 | 39 | void Widget::on_backroundColorButton_clicked() 40 | { 41 | QPalette palette = ui->label->palette(); 42 | QColor color = palette.color(QPalette::Window); 43 | QColor chosenColor = QColorDialog::getColor(color,this,"Choose color"); 44 | 45 | if(chosenColor.isValid()) 46 | { 47 | palette.setColor(QPalette::Window,chosenColor); 48 | ui->label->setPalette(palette); 49 | qDebug() << "User choose a valid color"; 50 | }else 51 | { 52 | qDebug() << "User choose a invalid color"; 53 | } 54 | 55 | } 56 | 57 | 58 | void Widget::on_fontButton_clicked() 59 | { 60 | bool ok; 61 | QFont font = QFontDialog::getFont( 62 | &ok, QFont("Helvetica [Cronyx]", 10), this); 63 | if (ok) { 64 | ui->label->setFont(font); 65 | } else { 66 | 67 | } 68 | } 69 | 70 | -------------------------------------------------------------------------------- /4.SignalsAndSlots/4-4CaloryCounter/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | 10 | //Initializer the members with values from the ui 11 | m_person.setWeight(ui->weightSpinBox->value()); 12 | m_time = ui->timeSpinBox->value(); 13 | m_speed = ui->speedSpinBox->value(); 14 | 15 | //Connect ui components to respective slots 16 | connect(ui->weightSpinBox,&QDoubleSpinBox::valueChanged, 17 | this,&Widget::weight_changed); 18 | connect(ui->timeSpinBox,&QDoubleSpinBox::valueChanged, 19 | this,&Widget::time_changed); 20 | connect(ui->speedSpinBox,&QDoubleSpinBox::valueChanged, 21 | this,&Widget::speed_changed); 22 | 23 | //Display the calory count 24 | connect(this,&Widget::calory_count_changed,[=](){ 25 | ui->caloryCountLabel->setText(QString::number(m_calory_count)); 26 | }); 27 | 28 | calculate_calories(); 29 | } 30 | 31 | Widget::~Widget() 32 | { 33 | delete ui; 34 | } 35 | 36 | void Widget::calculate_calories() 37 | { 38 | //CB = [0.0215 x KPH^3 - 0.1765 x KPH^2 + 0.8710 x KPH + 1.4577] x WKG x T 39 | m_calory_count = ( (0.0215 * (m_speed * m_speed * m_speed)) - (0.1765 * (m_speed * m_speed)) 40 | +(0.8710 * m_speed) + 1.4577) * m_person.weight() * m_time; 41 | emit calory_count_changed(); 42 | 43 | } 44 | 45 | void Widget::weight_changed(double weight) 46 | { 47 | m_person.setWeight(weight); 48 | calculate_calories(); 49 | } 50 | 51 | void Widget::time_changed(double time) 52 | { 53 | m_time = time; 54 | calculate_calories(); 55 | } 56 | 57 | void Widget::speed_changed(double speed) 58 | { 59 | m_speed = speed; 60 | calculate_calories(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /2.GettingStarted/2-14NumberGuessGui/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 462 10 | 234 11 | 12 | 13 | 14 | Guess My Number 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 22 | 23 | 24 | 25 | Guess My Number 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 1 35 | 36 | 37 | 10 38 | 39 | 40 | 41 | 42 | 43 | 44 | Guess 45 | 46 | 47 | 48 | 49 | 50 | 51 | Start Over 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | TextLabel 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /8.Styling/8-2StyleSheetInline/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 207 10 | 225 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 20 22 | 23 | 24 | 25 | color: rgb(85, 170, 255); 26 | background-color: rgb(255, 255, 0); 27 | 28 | 29 | Text1 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 20 38 | 39 | 40 | 41 | Text2 42 | 43 | 44 | 45 | 46 | 47 | 48 | Click 49 | 50 | 51 | 52 | 53 | 54 | 55 | PushButton 56 | 57 | 58 | 59 | 60 | 61 | 62 | PushButton 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-1QWidget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-1QWidget VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | rockwidget.h 20 | rockwidget.cpp 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(5-1QWidget 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET 5-1QWidget APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 30 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 31 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 32 | else() 33 | if(ANDROID) 34 | add_library(5-1QWidget SHARED 35 | ${PROJECT_SOURCES} 36 | ) 37 | # Define properties for Android with Qt 5 after find_package() calls as: 38 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 39 | else() 40 | add_executable(5-1QWidget 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(5-1QWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(5-1QWidget PROPERTIES 49 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 50 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 51 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 52 | MACOSX_BUNDLE TRUE 53 | WIN32_EXECUTABLE TRUE 54 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(5-1QWidget) 58 | endif() 59 | -------------------------------------------------------------------------------- /1.EnvironmentSetup/1-1Teaser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(1-1Teaser VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(1-1Teaser 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 1-1Teaser APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(1-1Teaser SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(1-1Teaser 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(1-1Teaser PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(1-1Teaser PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(1-1Teaser) 59 | endif() 60 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-4QTreeWidget/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include "./ui_widget.h" 3 | 4 | Widget::Widget(QWidget *parent) 5 | : QWidget(parent) 6 | , ui(new Ui::Widget) 7 | { 8 | ui->setupUi(this); 9 | ui->treeWidget->setColumnCount(2); 10 | 11 | //Set header data 12 | ui->treeWidget->setHeaderLabels(QStringList() << "ID" << "Name"); 13 | 14 | //Add data 15 | QTreeWidgetItem *treeItem1 = new QTreeWidgetItem(ui->treeWidget); 16 | treeItem1->setText(0, "11"); 17 | treeItem1->setText(1, "Snow"); 18 | 19 | QTreeWidgetItem *treeItem2 = new QTreeWidgetItem(ui->treeWidget); 20 | treeItem2->setText(0, "22"); 21 | treeItem2->setText(1, "David"); 22 | 23 | QTreeWidgetItem *treeItem3 = new QTreeWidgetItem(); // We don't give it an affiliation 24 | treeItem3->setText(0, "33"); 25 | treeItem3->setText(1, "Steve"); 26 | 27 | //Add item3 as a child of item2 28 | treeItem2->addChild(treeItem3); 29 | } 30 | 31 | Widget::~Widget() 32 | { 33 | delete ui; 34 | } 35 | 36 | 37 | void Widget::on_listItemsButton_clicked() 38 | { 39 | for(size_t i{}; i < ui->treeWidget->topLevelItemCount();++i){ 40 | auto item = ui->treeWidget->topLevelItem(i); 41 | if(item){ 42 | qDebug() << item->data(0,Qt::DisplayRole).toString() << "," 43 | << item->data(1,Qt::DisplayRole).toString(); 44 | //Look for children 45 | if(item->childCount()!=0){ 46 | for(size_t j{}; j < ui->treeWidget->topLevelItemCount();++j){ 47 | auto child = item->child(j); 48 | if(child){ 49 | qDebug() <<"---"<< child->data(0,Qt::DisplayRole).toString() << "," 50 | << child->data(1,Qt::DisplayRole).toString(); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-5QLineEdit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-5QLineEdit VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(5-5QLineEdit 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET 5-5QLineEdit APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 30 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 31 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 32 | else() 33 | if(ANDROID) 34 | add_library(5-5QLineEdit SHARED 35 | ${PROJECT_SOURCES} 36 | ) 37 | # Define properties for Android with Qt 5 after find_package() calls as: 38 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 39 | else() 40 | add_executable(5-5QLineEdit 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(5-5QLineEdit PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(5-5QLineEdit PROPERTIES 49 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 50 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 51 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 52 | MACOSX_BUNDLE TRUE 53 | WIN32_EXECUTABLE TRUE 54 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(5-5QLineEdit) 58 | endif() 59 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-6QTextEdit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-6QTextEdit VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(5-6QTextEdit 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET 5-6QTextEdit APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 30 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 31 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 32 | else() 33 | if(ANDROID) 34 | add_library(5-6QTextEdit SHARED 35 | ${PROJECT_SOURCES} 36 | ) 37 | # Define properties for Android with Qt 5 after find_package() calls as: 38 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 39 | else() 40 | add_executable(5-6QTextEdit 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(5-6QTextEdit PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(5-6QTextEdit PROPERTIES 49 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 50 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 51 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 52 | MACOSX_BUNDLE TRUE 53 | WIN32_EXECUTABLE TRUE 54 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(5-6QTextEdit) 58 | endif() 59 | -------------------------------------------------------------------------------- /8.Styling/8-1QPalette/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(8-1QPalette VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(8-1QPalette 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 8-1QPalette APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(8-1QPalette SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(8-1QPalette 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(8-1QPalette PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(8-1QPalette PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(8-1QPalette) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-3QMessageBox/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-3QMessageBox VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(5-3QMessageBox 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET 5-3QMessageBox APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 30 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 31 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 32 | else() 33 | if(ANDROID) 34 | add_library(5-3QMessageBox SHARED 35 | ${PROJECT_SOURCES} 36 | ) 37 | # Define properties for Android with Qt 5 after find_package() calls as: 38 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 39 | else() 40 | add_executable(5-3QMessageBox 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(5-3QMessageBox PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(5-3QMessageBox PROPERTIES 49 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 50 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 51 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 52 | MACOSX_BUNDLE TRUE 53 | WIN32_EXECUTABLE TRUE 54 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(5-3QMessageBox) 58 | endif() 59 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-4QPushButton/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-4QPushButton VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(5-4QPushButton 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET 5-4QPushButton APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 30 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 31 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 32 | else() 33 | if(ANDROID) 34 | add_library(5-4QPushButton SHARED 35 | ${PROJECT_SOURCES} 36 | ) 37 | # Define properties for Android with Qt 5 after find_package() calls as: 38 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 39 | else() 40 | add_executable(5-4QPushButton 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(5-4QPushButton PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(5-4QPushButton PROPERTIES 49 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 50 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 51 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 52 | MACOSX_BUNDLE TRUE 53 | WIN32_EXECUTABLE TRUE 54 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(5-4QPushButton) 58 | endif() 59 | -------------------------------------------------------------------------------- /10.FilesDirectories/10-2QDirDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(10-2QDirDemo VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(10-2QDirDemo 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 10-2QDirDemo APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(10-2QDirDemo SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(10-2QDirDemo 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(10-2QDirDemo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(10-2QDirDemo PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(10-2QDirDemo) 59 | endif() 60 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-6QTVQSIM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(11-6QTVQSIM VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(11-6QTVQSIM 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 11-6QTVQSIM APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(11-6QTVQSIM SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(11-6QTVQSIM 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(11-6QTVQSIM PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(11-6QTVQSIM PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(11-6QTVQSIM) 59 | endif() 60 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-7QTVQFSM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(11-7QTVQFSM VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(11-7QTVQFSM 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 11-7QTVQFSM APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(11-7QTVQFSM SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(11-7QTVQFSM 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(11-7QTVQFSM PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(11-7QTVQFSM PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(11-7QTVQFSM) 59 | endif() 60 | -------------------------------------------------------------------------------- /2.GettingStarted/2-13GuiIntro/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(2-13GuiIntro VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(2-13GuiIntro 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 2-13GuiIntro APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(2-13GuiIntro SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(2-13GuiIntro 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(2-13GuiIntro PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(2-13GuiIntro PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(2-13GuiIntro) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-7QLabel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-7QLabel VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | resource.qrc 23 | ) 24 | 25 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 26 | qt_add_executable(5-7QLabel 27 | MANUAL_FINALIZATION 28 | ${PROJECT_SOURCES} 29 | ) 30 | # Define target properties for Android with Qt 6 as: 31 | # set_property(TARGET 5-7QLabel APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 32 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 33 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 34 | else() 35 | if(ANDROID) 36 | add_library(5-7QLabel SHARED 37 | ${PROJECT_SOURCES} 38 | ) 39 | # Define properties for Android with Qt 5 after find_package() calls as: 40 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 41 | else() 42 | add_executable(5-7QLabel 43 | ${PROJECT_SOURCES} 44 | ) 45 | endif() 46 | endif() 47 | 48 | target_link_libraries(5-7QLabel PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 49 | 50 | set_target_properties(5-7QLabel PROPERTIES 51 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 52 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 53 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 54 | MACOSX_BUNDLE TRUE 55 | WIN32_EXECUTABLE TRUE 56 | ) 57 | 58 | if(QT_VERSION_MAJOR EQUAL 6) 59 | qt_finalize_executable(5-7QLabel) 60 | endif() 61 | -------------------------------------------------------------------------------- /1.EnvironmentSetup/1-1Teaser/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 306 10 | 293 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | LastName : 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | FirstName : 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Message : 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Submit 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-2QMainWindow/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-2QMainWindow VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | mainwindow.h 20 | mainwindow.cpp 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(5-2QMainWindow 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET 5-2QMainWindow APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 30 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 31 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 32 | else() 33 | if(ANDROID) 34 | add_library(5-2QMainWindow SHARED 35 | ${PROJECT_SOURCES} 36 | ) 37 | # Define properties for Android with Qt 5 after find_package() calls as: 38 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 39 | else() 40 | add_executable(5-2QMainWindow 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(5-2QMainWindow PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(5-2QMainWindow PROPERTIES 49 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 50 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 51 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 52 | MACOSX_BUNDLE TRUE 53 | WIN32_EXECUTABLE TRUE 54 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(5-2QMainWindow) 58 | endif() 59 | -------------------------------------------------------------------------------- /10.FilesDirectories/10-1QFileDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(10-1QFileDemo VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(10-1QFileDemo 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 10-1QFileDemo APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(10-1QFileDemo SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(10-1QFileDemo 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(10-1QFileDemo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(10-1QFileDemo PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(10-1QFileDemo) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-16QComboBox/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-16QComboBox VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(5-16QComboBox 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 5-16QComboBox APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(5-16QComboBox SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(5-16QComboBox 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(5-16QComboBox PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(5-16QComboBox PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(5-16QComboBox) 59 | endif() 60 | -------------------------------------------------------------------------------- /6.Dialogs/6-3QFileDialog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(6-3QFileDialog VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(6-3QFileDialog 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 6-3QFileDialog APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(6-3QFileDialog SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(6-3QFileDialog 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(6-3QFileDialog PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(6-3QFileDialog PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(6-3QFileDialog) 59 | endif() 60 | -------------------------------------------------------------------------------- /6.Dialogs/6-4QFontDialog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(6-4QFontDialog VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(6-4QFontDialog 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 6-4QFontDialog APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(6-4QFontDialog SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(6-4QFontDialog 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(6-4QFontDialog PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(6-4QFontDialog PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(6-4QFontDialog) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-15QTabWidget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-15QTabWidget VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(5-15QTabWidget 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 5-15QTabWidget APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(5-15QTabWidget SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(5-15QTabWidget 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(5-15QTabWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(5-15QTabWidget PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(5-15QTabWidget) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-8QHBoxLayout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-8QHBoxLayout VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(5-8QHBoxLayout 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 5-8QHBoxLayout APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(5-8QHBoxLayout SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(5-8QHBoxLayout 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(5-8QHBoxLayout PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(5-8QHBoxLayout PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(5-8QHBoxLayout) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-9QVBoxLayout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-9QVBoxLayout VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(5-9QVBoxLayout 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 5-9QVBoxLayout APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(5-9QVBoxLayout SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(5-9QVBoxLayout 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(5-9QVBoxLayout PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(5-9QVBoxLayout PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(5-9QVBoxLayout) 59 | endif() 60 | -------------------------------------------------------------------------------- /6.Dialogs/6-5QColorDialog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(6-5QColorDialog VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(6-5QColorDialog 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 6-5QColorDialog APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(6-5QColorDialog SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(6-5QColorDialog 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(6-5QColorDialog PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(6-5QColorDialog PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(6-5QColorDialog) 59 | endif() 60 | -------------------------------------------------------------------------------- /6.Dialogs/6-6QInputDialog/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(6-6QInputDialog VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(6-6QInputDialog 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 6-6QInputDialog APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(6-6QInputDialog SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(6-6QInputDialog 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(6-6QInputDialog PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(6-6QInputDialog PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(6-6QInputDialog) 59 | endif() 60 | -------------------------------------------------------------------------------- /8.Styling/8-3ExternalStyleSheets/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 350 10 | 156 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Last Name : 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | First Name : 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Proffession : 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | Submit 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-11QGridLayout/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-11QGridLayout VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(5-11QGridLayout 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 5-11QGridLayout APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(5-11QGridLayout SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(5-11QGridLayout 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(5-11QGridLayout PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(5-11QGridLayout PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(5-11QGridLayout) 59 | endif() 60 | -------------------------------------------------------------------------------- /5.ATourOfQtWidgets/5-14QListWidget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(5-14QListWidget VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(5-14QListWidget 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 5-14QListWidget APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(5-14QListWidget SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(5-14QListWidget 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(5-14QListWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(5-14QListWidget PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(5-14QListWidget) 59 | endif() 60 | -------------------------------------------------------------------------------- /6.Dialogs/6-5QColorDialog/widget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Widget 4 | 5 | 6 | 7 | 0 8 | 0 9 | 359 10 | 96 11 | 12 | 13 | 14 | Widget 15 | 16 | 17 | 18 | 19 | 20 | 21 | 16 22 | 23 | 24 | 25 | Some Text 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | Qt::Horizontal 35 | 36 | 37 | 38 | 40 39 | 20 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | Text Color 48 | 49 | 50 | 51 | 52 | 53 | 54 | Background Color 55 | 56 | 57 | 58 | 59 | 60 | 61 | Font 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /9.Settings/9-2QSettingsDemo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(9-2QSettingsDemo VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(9-2QSettingsDemo 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 9-2QSettingsDemo APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(9-2QSettingsDemo SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(9-2QSettingsDemo 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(9-2QSettingsDemo PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(9-2QSettingsDemo PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(9-2QSettingsDemo) 59 | endif() 60 | -------------------------------------------------------------------------------- /11.ModelViewArchitecture/11-4QTreeWidget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(11-4QTreeWidget VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | set(CMAKE_AUTOUIC ON) 8 | set(CMAKE_AUTOMOC ON) 9 | set(CMAKE_AUTORCC ON) 10 | 11 | set(CMAKE_CXX_STANDARD 11) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | 14 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | widget.cpp 20 | widget.h 21 | widget.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(11-4QTreeWidget 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET 11-4QTreeWidget APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 31 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 32 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 33 | else() 34 | if(ANDROID) 35 | add_library(11-4QTreeWidget SHARED 36 | ${PROJECT_SOURCES} 37 | ) 38 | # Define properties for Android with Qt 5 after find_package() calls as: 39 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 40 | else() 41 | add_executable(11-4QTreeWidget 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(11-4QTreeWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(11-4QTreeWidget PROPERTIES 50 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 51 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 52 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 53 | MACOSX_BUNDLE TRUE 54 | WIN32_EXECUTABLE TRUE 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(11-4QTreeWidget) 59 | endif() 60 | --------------------------------------------------------------------------------