├── .gitignore ├── LICENSE ├── README.md └── src ├── collections_and_algorithms ├── qlist │ ├── CMakeLists.txt │ └── main.cpp ├── qlist_vs_qvector │ ├── CMakeLists.txt │ └── main.cpp ├── qmap │ ├── CMakeLists.txt │ └── main.cpp └── qset │ ├── CMakeLists.txt │ └── main.cpp ├── concurrent_computing ├── cmd_interface │ ├── CMakeLists.txt │ ├── cmd_interface.cpp │ ├── cmd_interface.h │ └── main.cpp ├── gui_thread.cpp │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main_window.cpp │ ├── main_window.h │ └── main_window.ui ├── spawn_process │ ├── CMakeLists.txt │ └── main.cpp └── spawn_thread │ ├── CMakeLists.txt │ └── main.cpp ├── core ├── cpp │ ├── children_generator │ │ ├── CMakeLists.txt │ │ ├── children_generator.cpp │ │ ├── children_generator.h │ │ └── main.cpp │ ├── custom_signal_slots │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ ├── qvariant_and_qmetatype │ │ ├── CMakeLists.txt │ │ ├── custom_type.cpp │ │ ├── custom_type.h │ │ └── main.cpp │ └── smart_pointers │ │ ├── CMakeLists.txt │ │ └── main.cpp └── python │ └── custom_signal_slots │ ├── main.py │ ├── main_window.ui │ └── requirements.txt ├── files ├── cpp │ ├── file_info │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── file_operations │ │ ├── CMakeLists.txt │ │ └── main.cpp │ ├── json_serialization │ │ ├── CMakeLists.txt │ │ ├── json_serializable_interface.h │ │ ├── main.cpp │ │ ├── player.cpp │ │ └── player.h │ └── storage_info │ │ ├── CMakeLists.txt │ │ └── main.cpp └── python │ ├── file_info │ ├── main.py │ └── requirements.txt │ ├── file_operations │ ├── main.py │ └── requirements.txt │ ├── json_serialization │ ├── json_serializable_interface.py │ ├── json_utils.py │ ├── main.py │ ├── player.py │ └── requirements.txt │ └── storage_info │ ├── main.py │ └── requirements.txt ├── graphics ├── cpp │ ├── image_cropper │ │ ├── CMakeLists.txt │ │ ├── image_cropper.cpp │ │ ├── image_cropper.h │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ ├── movable_image │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ ├── main_window.ui │ │ ├── movable_image.cpp │ │ └── movable_image.h │ ├── moving_balls │ │ ├── CMakeLists.txt │ │ ├── bordered_scene.cpp │ │ ├── bordered_scene.h │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ ├── main_window.ui │ │ ├── movable_image.cpp │ │ └── movable_image.h │ └── transformations │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ ├── main_window.ui │ │ ├── transformation_display.cpp │ │ └── transformation_display.h └── python │ ├── image_cropper │ ├── image_cropper.py │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ └── requirements.txt │ ├── movable_image │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ ├── movable_image.py │ └── requirements.txt │ ├── moving_balls │ ├── bordered_scene.py │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ ├── movable_image.py │ └── requirements.txt │ └── transformations │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ ├── requirements.txt │ └── transformation_display.py ├── mvc ├── cpp │ ├── crypto_ranking │ │ ├── CMakeLists.txt │ │ ├── crypto_ranking_data.h │ │ ├── crypto_ranking_delegate.cpp │ │ ├── crypto_ranking_delegate.h │ │ ├── crypto_ranking_table.cpp │ │ ├── crypto_ranking_table.h │ │ ├── images │ │ │ ├── bitcoin.png │ │ │ ├── bitcoin_cash.png │ │ │ ├── down.png │ │ │ ├── ethereum.png │ │ │ ├── litecoin.png │ │ │ ├── ripple.png │ │ │ └── up.png │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ ├── emoji_picker │ │ ├── CMakeLists.txt │ │ ├── emoji_picker_data.h │ │ ├── emoji_picker_delegate.cpp │ │ ├── emoji_picker_delegate.h │ │ ├── emoji_picker_tree.cpp │ │ ├── emoji_picker_tree.h │ │ ├── images │ │ │ ├── boredom.png │ │ │ ├── crying.png │ │ │ ├── emoji.png │ │ │ ├── happy.png │ │ │ ├── hearts.png │ │ │ ├── in_love.png │ │ │ ├── laugh.png │ │ │ ├── love.png │ │ │ ├── nerd.png │ │ │ ├── party.png │ │ │ ├── shame.png │ │ │ ├── sleeping.png │ │ │ ├── smile.png │ │ │ ├── star.png │ │ │ ├── thinking.png │ │ │ └── upside_down.png │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ ├── file_directory_treeview │ │ ├── CMakeLists.txt │ │ ├── clickable_tree_view.cpp │ │ ├── clickable_tree_view.h │ │ ├── file_dir_model.cpp │ │ ├── file_dir_model.h │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ ├── item_delegate │ │ ├── CMakeLists.txt │ │ ├── custom_delegate.cpp │ │ ├── custom_delegate.h │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ ├── reorderable_treeview │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ ├── main_window.ui │ │ ├── reordable_tree_view.h │ │ ├── reorderable_tree_view.cpp │ │ ├── tree_model.cpp │ │ └── tree_model.h │ ├── string_list_model │ │ ├── CMakeLists.txt │ │ ├── insert_element_dialog.cpp │ │ ├── insert_element_dialog.h │ │ ├── insert_element_dialog.ui │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui │ └── tree_model │ │ ├── CMakeLists.txt │ │ ├── clickable_tree_view.cpp │ │ ├── clickable_tree_view.h │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ ├── main_window.ui │ │ ├── tree_model.cpp │ │ └── tree_model.h └── python │ ├── crypto_ranking │ ├── crypto_ranking_data.py │ ├── crypto_ranking_delegate.py │ ├── crypto_ranking_table.py │ ├── images │ │ ├── bitcoin.png │ │ ├── bitcoin_cash.png │ │ ├── down.png │ │ ├── ethereum.png │ │ ├── litecoin.png │ │ ├── ripple.png │ │ └── up.png │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ └── requirements.txt │ ├── emoji_picker │ ├── emoji_picker_data.py │ ├── emoji_picker_delegate.py │ ├── emoji_picker_tree.py │ ├── images │ │ ├── boredom.png │ │ ├── crying.png │ │ ├── emoji.png │ │ ├── happy.png │ │ ├── hearts.png │ │ ├── in_love.png │ │ ├── laugh.png │ │ ├── love.png │ │ ├── nerd.png │ │ ├── party.png │ │ ├── shame.png │ │ ├── sleeping.png │ │ ├── smile.png │ │ ├── star.png │ │ ├── thinking.png │ │ └── upside_down.png │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ └── requirements.txt │ ├── file_directory_treeview │ ├── main.py │ └── requirements.txt │ ├── item_delegate │ ├── custom_delegate.py │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ └── requirements.txt │ ├── matrix_view │ ├── checkable_matrix_view.py │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ ├── matrix_view.py │ └── requirements.txt │ ├── reorderable_treeview │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ ├── reorderable_tree_model.py │ ├── reorderable_tree_view.py │ ├── requirements.txt │ └── tree_model.py │ ├── string_list_model │ ├── insert_element_dialog.py │ ├── insert_element_dialog.ui │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ └── requirements.txt │ └── tree_model │ ├── clickable_tree_view.py │ ├── main.py │ ├── main_window.py │ ├── main_window.ui │ ├── requirements.txt │ └── tree_model.py ├── network └── temp ├── other ├── cpp │ ├── build_with_docker │ │ └── temp.md │ ├── system_info │ │ ├── CMakeLists.txt │ │ └── main.cpp │ └── webcam │ │ ├── CMakeLists.txt │ │ ├── main.cpp │ │ ├── main_window.cpp │ │ ├── main_window.h │ │ └── main_window.ui └── python │ ├── build_with_docker │ └── temp.md │ └── resources_and_pyinstaller │ └── temp.md ├── plots ├── altair │ └── temp.md ├── matplotlib │ ├── filter_histogram │ │ ├── double_range_slider.py │ │ ├── filter_histogram.py │ │ ├── filter_histogram.ui │ │ ├── histogram_plot.py │ │ ├── main.py │ │ ├── main_window.py │ │ ├── main_window.ui │ │ ├── plot_widget.py │ │ ├── plot_widget_interface.py │ │ └── requirements.txt │ ├── lasso_scatter_plot │ │ ├── checkable_matrix_view.py │ │ ├── lasso_scatter.py │ │ ├── main.py │ │ ├── main_window.py │ │ ├── main_window.ui │ │ ├── matrix_view.py │ │ ├── plot_widget.py │ │ ├── plot_widget_interface.py │ │ ├── requirements.txt │ │ └── toggle_button.py │ └── plot_widget │ │ ├── main.py │ │ ├── main_window.py │ │ ├── main_window.ui │ │ ├── plot_widget.py │ │ ├── plot_widget_interface.py │ │ └── requirements.txt └── plotly │ └── temp.md ├── themes ├── bright_vibrant │ └── temp.md ├── classic_dark_mode │ └── temp.md ├── colorful_flat │ └── temp.md ├── minimal_muted │ └── temp.md ├── minimalist_monochrome │ └── temp.md └── pastel_color │ └── temp.md └── widgets ├── cpp ├── custom_painting │ ├── CMakeLists.txt │ ├── arrow_box.cpp │ ├── arrow_box.h │ ├── main.cpp │ ├── main_window.cpp │ ├── main_window.h │ └── main_window.ui ├── custom_tooltip │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main_window.cpp │ ├── main_window.h │ └── main_window.ui ├── message_box │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main_window.cpp │ ├── main_window.h │ └── main_window.ui ├── status_bar │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main_window.cpp │ ├── main_window.h │ ├── main_window.ui │ ├── status_bar.cpp │ └── status_bar.h └── switch_button │ └── temp.md └── python ├── custom_painting ├── arrow_box.py ├── main.py ├── main_window.ui └── requirements.txt ├── custom_tooltip ├── main.py ├── main_window.ui └── requirements.txt ├── double_range_slider ├── double_range_slider.py ├── main.py ├── main_window.py ├── main_window.ui └── requirements.txt ├── message_box ├── main.py ├── main_window.ui └── requirements.txt ├── status_bar ├── main.py ├── main_window.ui ├── requirements.txt └── status_bar.py ├── switch_button ├── main.py ├── main_window.py ├── main_window.ui ├── requirements.txt └── switch_button.py └── toggle_button ├── main.py ├── main_window.py ├── main_window.ui ├── requirements.txt └── toggle_button.py /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Qt 3 | ################# 4 | *.moc 5 | moc_*.cpp 6 | qrc_*.cpp 7 | ui_*.h 8 | *.user* 9 | 10 | ################# 11 | ## Linux 12 | ################# 13 | Makefile 14 | *.o 15 | *.so 16 | *.a 17 | *.swp 18 | 19 | ################# 20 | ## Visual Studio 21 | ################# 22 | *json* 23 | *.suo 24 | *.sln.docstates 25 | [Dd]ebug/ 26 | [Rr]elease/ 27 | *_i.c 28 | *_p.c 29 | *.ilk 30 | *.meta 31 | *.obj 32 | *.pch 33 | *.pdb 34 | *.pgc 35 | *.pgd 36 | *.rsp 37 | *.sbr 38 | *.tlb 39 | *.tli 40 | *.tlh 41 | *.tmp 42 | *.vspscc 43 | .builds 44 | *.dotCover 45 | ipch/ 46 | *.aps 47 | *.ncb 48 | *.opensdf 49 | *.sdf 50 | *.psess 51 | *.vsp 52 | *.xml 53 | *.idea* 54 | 55 | 56 | ############ 57 | ## Windows 58 | ############ 59 | Thumbs.db 60 | Desktop.ini 61 | 62 | # Unit test / coverage reports 63 | .coverage 64 | .tox 65 | 66 | #Translations 67 | *.mo 68 | 69 | ############ 70 | ## Builds 71 | ############ 72 | *build* 73 | 74 | 75 | *__pycache__* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Adam Djellouli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qlist/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(qlist 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qlist/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void fillList(QList &list, int size) { 7 | list.clear(); 8 | for (int i = 0; i < size; i++) { 9 | auto obj = new QObject(); 10 | obj->setObjectName(QString("obj%1").arg(i)); 11 | list.append(obj); 12 | } 13 | } 14 | 15 | void displayList(QList &list) { 16 | qDebug() << "List:"; 17 | for (auto obj : list) { 18 | qDebug() << obj->objectName(); 19 | } 20 | } 21 | 22 | auto findObject(QList &list, QString name) -> int { 23 | int index = -1; 24 | for (int i = 0; i < list.size(); i++) { 25 | if (list.at(i)->objectName() == name) { 26 | index = i; 27 | break; 28 | } 29 | } 30 | return index; 31 | } 32 | 33 | void deleteObject(QList &list, QString name) { 34 | int index = findObject(list, name); 35 | if (index != -1) { 36 | delete list.at(index); 37 | list.removeAt(index); 38 | } 39 | } 40 | 41 | auto main(int /*argc*/, char * /*argv*/[]) -> int { 42 | 43 | QList list; 44 | fillList(list, 10); 45 | displayList(list); 46 | 47 | deleteObject(list, "obj5"); 48 | displayList(list); 49 | 50 | qDebug() << "Index of obj3: " << findObject(list, "obj3"); 51 | qDebug() << "Index of obj5: " << findObject(list, "obj5"); 52 | 53 | qDebug() << "List size: " << list.size(); 54 | 55 | qDeleteAll(list); // delete all objects in list 56 | qDebug() << "List size: " 57 | << list.size(); // the objects are still in the list, but the 58 | // pointers are invalid 59 | 60 | list.clear(); 61 | qDebug() << "List size: " 62 | << list.size(); // the objects are deleted, the list is empty 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qlist_vs_qvector/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(qlist_vs_qvector 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qlist_vs_qvector/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | template void fillContainer(T &container, int size) { 8 | for (int i = 0; i < size; ++i) { 9 | auto obj = new QObject(); 10 | obj->setObjectName(QString("Obj%1").arg(i)); 11 | container.append(obj); 12 | } 13 | } 14 | 15 | template void displayDistances(T &container) { 16 | 17 | qDebug() << "Displaying distances for container " << container; 18 | 19 | for (int i = 1; i < container.length(); i++) { 20 | auto previous = reinterpret_cast(&container.at(i - 1)); 21 | auto current = reinterpret_cast(&container.at(i)); 22 | auto distance = current - previous; 23 | 24 | qDebug() << "Distance between " << i - 1 << " and " << i << " is " 25 | << distance; 26 | } 27 | } 28 | 29 | auto main(int /*argc*/, char * /*argv*/[]) -> int { 30 | 31 | QList list; 32 | fillContainer(list, 10); 33 | displayDistances(list); 34 | 35 | QVector vector; 36 | fillContainer(vector, 10); 37 | displayDistances(vector); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qmap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(qmap 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qset/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(qset 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/collections_and_algorithms/qset/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void fillSet(QSet &set, int size) { 7 | for (int i = 0; i < size; ++i) { 8 | auto obj = new QObject; 9 | obj->setObjectName(QString("Obj%1").arg(i)); 10 | set.insert(obj); 11 | } 12 | } 13 | 14 | void displaySet(const QSet &set) { 15 | qDebug() << "Set:"; 16 | foreach (QObject *obj, set) { qDebug() << obj->objectName(); } 17 | } 18 | 19 | auto main(int /*argc*/, char * /*argv*/[]) -> int { 20 | 21 | QSet set; 22 | fillSet(set, 10); 23 | displaySet(set); // not in order 24 | 25 | // what will happen if we insert the same object twice? 26 | auto obj = new QObject; 27 | obj->setObjectName("ObjX"); 28 | set.insert(obj); 29 | set.insert(obj); 30 | displaySet(set); // not in order 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/concurrent_computing/cmd_interface/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(cmd_interface 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 | cmd_interface.cpp 20 | cmd_interface.h 21 | ) 22 | 23 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 24 | qt_add_executable(${PROJECT_NAME} 25 | MANUAL_FINALIZATION 26 | ${PROJECT_SOURCES} 27 | ) 28 | # Define target properties for Android with Qt 6 as: 29 | # set_property(TARGET ${PROJECT_NAME} 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(${PROJECT_NAME} 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(${PROJECT_NAME} 41 | ${PROJECT_SOURCES} 42 | ) 43 | endif() 44 | endif() 45 | 46 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 47 | 48 | set_target_properties(${PROJECT_NAME} 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 | ) 53 | 54 | if(QT_VERSION_MAJOR EQUAL 6) 55 | qt_finalize_executable(${PROJECT_NAME}) 56 | endif() 57 | -------------------------------------------------------------------------------- /src/concurrent_computing/cmd_interface/cmd_interface.cpp: -------------------------------------------------------------------------------- 1 | #include "cmd_interface.h" 2 | #include 3 | 4 | CmdInterface::CmdInterface(QObject *parent) : QObject(parent) { 5 | #ifdef __linux__ 6 | const QString executable_path = "/bin/bash"; 7 | #elif _WIN32 8 | const QString executable_path = "C:/windows/system32/cmd.exe"; 9 | #else 10 | throw std::runtime_error("Unsupported OS"); 11 | #endif 12 | 13 | proc.setProgram(executable_path); 14 | proc.start(); 15 | connect(&proc, &QProcess::readyRead, this, &CmdInterface::readyRead); 16 | connect(&proc, &QProcess::readyReadStandardOutput, this, 17 | &CmdInterface::readyRead); 18 | connect(&proc, &QProcess::readyReadStandardError, this, 19 | &CmdInterface::readyRead); 20 | } 21 | 22 | CmdInterface::~CmdInterface() { 23 | if (proc.isOpen()) 24 | proc.terminate(); 25 | } 26 | 27 | void CmdInterface::readyRead() { 28 | qint64 value = 0; 29 | do { 30 | QByteArray line = proc.readAll(); 31 | qDebug() << line.trimmed(); 32 | value = line.length(); 33 | } while (value > 0); 34 | } 35 | 36 | void CmdInterface::action(QByteArray data) { 37 | if (!data.endsWith(endl.toLatin1())) { 38 | for (auto ch : endl) 39 | data.append(ch.toLatin1()); 40 | } 41 | proc.write(data); 42 | proc.waitForBytesWritten(1000); 43 | } 44 | -------------------------------------------------------------------------------- /src/concurrent_computing/cmd_interface/cmd_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #ifdef __linux__ 6 | const QString endl("\n"); 7 | #elif _WIN32 8 | const QString endl("\r\n"); 9 | #else 10 | const QString endl("\r"); 11 | #endif 12 | 13 | class CmdInterface : public QObject { 14 | Q_OBJECT 15 | public: 16 | CmdInterface(QObject *parent = nullptr); 17 | ~CmdInterface(); 18 | signals: 19 | 20 | public slots: 21 | void readyRead(); 22 | void action(QByteArray data); 23 | 24 | private: 25 | QProcess proc; 26 | }; 27 | -------------------------------------------------------------------------------- /src/concurrent_computing/cmd_interface/main.cpp: -------------------------------------------------------------------------------- 1 | #include "cmd_interface.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | QCoreApplication a(argc, argv); 6 | CmdInterface cmd; 7 | cmd.action(QByteArray("dir")); 8 | cmd.action(QByteArray("echo \"Hello World\"")); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/concurrent_computing/gui_thread.cpp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(gui_thread 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 | 15 | find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets Concurrent REQUIRED) 16 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Concurrent REQUIRED) 17 | 18 | set(PROJECT_SOURCES 19 | main.cpp 20 | main_window.cpp 21 | main_window.h 22 | main_window.ui 23 | ) 24 | 25 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 26 | qt_add_executable(${PROJECT_NAME} 27 | MANUAL_FINALIZATION 28 | ${PROJECT_SOURCES} 29 | ) 30 | # Define target properties for Android with Qt 6 as: 31 | # set_property(TARGET ${PROJECT_NAME} 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(${PROJECT_NAME} 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(${PROJECT_NAME} 43 | ${PROJECT_SOURCES} 44 | ) 45 | endif() 46 | endif() 47 | 48 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Concurrent) 49 | 50 | set_target_properties(${PROJECT_NAME} 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 | ) 55 | 56 | if(QT_VERSION_MAJOR EQUAL 6) 57 | qt_finalize_executable(${PROJECT_NAME}) 58 | endif() 59 | 60 | -------------------------------------------------------------------------------- /src/concurrent_computing/gui_thread.cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/concurrent_computing/gui_thread.cpp/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | 4 | #include 5 | 6 | int foo(int id) { 7 | qDebug() << "Starting worker function with id: " 8 | << QThread::currentThreadId(); 9 | QThread::sleep(1); 10 | qDebug() << "Worker function finished with id: " 11 | << QThread::currentThreadId(); 12 | 13 | return id; 14 | } 15 | 16 | MainWindow::MainWindow(QWidget *parent) 17 | : QMainWindow(parent), ui(new Ui::MainWindow), counter(0) { 18 | ui->setupUi(this); 19 | 20 | // connect push button with QtConcurrent::run and run single foo() function, 21 | // but use a watcher to wait till it's finished 22 | connect(ui->pushButton, &QPushButton::clicked, [this]() { 23 | auto future = QtConcurrent::run(foo, counter++); 24 | connect(&watcher, &QFutureWatcher::finished, this, [this, future]() { 25 | // display return result of foo() function 26 | ui->listWidget->addItem(QString("Thread id: 0x%1").arg(future.result())); 27 | }); 28 | ui->listWidget->clear(); 29 | watcher.setFuture(future); 30 | }); 31 | } 32 | 33 | MainWindow::~MainWindow() { delete ui; } 34 | -------------------------------------------------------------------------------- /src/concurrent_computing/gui_thread.cpp/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { 9 | class MainWindow; 10 | } 11 | QT_END_NAMESPACE 12 | 13 | class MainWindow : public QMainWindow { 14 | Q_OBJECT 15 | 16 | public: 17 | MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | 20 | private: 21 | Ui::MainWindow *ui; 22 | int counter; 23 | QFutureWatcher watcher; 24 | }; 25 | #endif // MAINWINDOW_H 26 | -------------------------------------------------------------------------------- /src/concurrent_computing/gui_thread.cpp/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Add 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 0 40 | 0 41 | 800 42 | 20 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/concurrent_computing/spawn_process/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(spawn_process 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 | ) 20 | 21 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 22 | qt_add_executable(${PROJECT_NAME} 23 | MANUAL_FINALIZATION 24 | ${PROJECT_SOURCES} 25 | ) 26 | # Define target properties for Android with Qt 6 as: 27 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 28 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 29 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 30 | else() 31 | if(ANDROID) 32 | add_library(${PROJECT_NAME} SHARED 33 | ${PROJECT_SOURCES} 34 | ) 35 | # Define properties for Android with Qt 5 after find_package() calls as: 36 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 37 | else() 38 | add_executable(${PROJECT_NAME} 39 | ${PROJECT_SOURCES} 40 | ) 41 | endif() 42 | endif() 43 | 44 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 45 | 46 | set_target_properties(${PROJECT_NAME} PROPERTIES 47 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 48 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 49 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 50 | ) 51 | 52 | if(QT_VERSION_MAJOR EQUAL 6) 53 | qt_finalize_executable(${PROJECT_NAME}) 54 | endif() 55 | -------------------------------------------------------------------------------- /src/concurrent_computing/spawn_process/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | QByteArray spawnProcess(QString program, QStringList arguments, 8 | QString message) { 9 | QProcess process; 10 | process.start(program, arguments); 11 | 12 | if (!process.waitForStarted()) 13 | throw std::runtime_error("Process failed to start"); 14 | 15 | if (!message.isEmpty()) { 16 | process.write(message.toUtf8()); 17 | process.closeWriteChannel(); 18 | } 19 | 20 | if (!process.waitForFinished()) 21 | throw std::runtime_error("Process failed to finish"); 22 | 23 | auto result = process.readAll(); 24 | qDebug() << process.readAll(); 25 | return result; 26 | } 27 | 28 | int main(int argc, char *argv[]) { 29 | 30 | QString program = "python"; 31 | QStringList arguments = {"example.py"}; 32 | QString message; 33 | 34 | try { 35 | auto result = spawnProcess(program, arguments, message); 36 | qDebug() << result; 37 | } catch (std::runtime_error &e) { 38 | qDebug() << e.what(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/concurrent_computing/spawn_thread/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(spawn_thread 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 Concurrent REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Concurrent REQUIRED) 16 | 17 | 18 | add_executable(spawn_thread 19 | main.cpp 20 | ) 21 | target_link_libraries(spawn_thread Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Concurrent) 22 | -------------------------------------------------------------------------------- /src/concurrent_computing/spawn_thread/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void foo() { 8 | qDebug() << "Starting worker function with id: " 9 | << QThread::currentThreadId(); 10 | QThread::sleep(1); 11 | qDebug() << "Worker function finished with id: " 12 | << QThread::currentThreadId(); 13 | } 14 | 15 | int main(int argc, char *argv[]) { 16 | 17 | // spawn 3 threads with QConcurrent::run and put them in QList 18 | QVector> futures; 19 | for (int i = 0; i < 3; ++i) { 20 | futures.append(QtConcurrent::run(foo)); 21 | } 22 | 23 | // wait for all threads to finish 24 | for (auto &future : futures) { 25 | future.waitForFinished(); 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/core/cpp/children_generator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(children_generator 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(${PROJECT_NAME} 18 | main.cpp 19 | children_generator.h 20 | children_generator.cpp 21 | ) 22 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 23 | -------------------------------------------------------------------------------- /src/core/cpp/children_generator/children_generator.cpp: -------------------------------------------------------------------------------- 1 | #include "children_generator.h" 2 | #include 3 | 4 | ChildrenGenerator::ChildrenGenerator(QString name, QObject *parent) 5 | : QObject(parent) { 6 | qDebug() << "Creating ChildrenGenerator object with name: " << name; 7 | this->setObjectName(name); 8 | } 9 | 10 | ChildrenGenerator::~ChildrenGenerator() { 11 | qDebug() << "Destroying ChildrenGenerator object with name: " 12 | << this->objectName(); 13 | } 14 | 15 | QObject *ChildrenGenerator::createChild(QString name) { 16 | qDebug() << "Creating child with name: " << name; 17 | try { 18 | auto child = new ChildrenGenerator(name, this); 19 | return child; 20 | } catch (...) { 21 | qDebug() << "Error creating child with name: " << name; 22 | return nullptr; 23 | } 24 | } 25 | 26 | void ChildrenGenerator::deleteChild(QString name) { 27 | qDebug() << "Attempting to delete child with name: " << name; 28 | auto child = this->findChild(name); 29 | if (child) { 30 | child->deleteLater(); 31 | } else { 32 | qDebug() << "Child not found"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/core/cpp/children_generator/children_generator.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_CORE_CHILDREN_GENERATOR_CHILDREN_GENERATOR_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_CORE_CHILDREN_GENERATOR_CHILDREN_GENERATOR_H 3 | 4 | #include 5 | #include 6 | 7 | class ChildrenGenerator : public QObject { 8 | Q_OBJECT 9 | public: 10 | ChildrenGenerator(QString name, QObject *parent = nullptr); 11 | ~ChildrenGenerator(); 12 | QObject *createChild(QString name); 13 | void deleteChild(QString name); 14 | }; 15 | 16 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_CORE_CHILDREN_GENERATOR_CHILDREN_GENERATOR_H 17 | -------------------------------------------------------------------------------- /src/core/cpp/children_generator/main.cpp: -------------------------------------------------------------------------------- 1 | #include "children_generator.h" 2 | #include 3 | #include 4 | 5 | auto main(int /*argc*/, char * /*argv*/[]) -> int { 6 | 7 | auto root = new ChildrenGenerator("root"); 8 | 9 | for (int i = 0; i < 10; ++i) { 10 | auto child = root->createChild("child" + QString::number(i)); 11 | if (child) { 12 | qDebug() << "Created child with name: " << child->objectName(); 13 | } else { 14 | qDebug() << "Error creating child with name: " 15 | << "child" + QString::number(i); 16 | } 17 | } 18 | 19 | // Display number of children 20 | qDebug() << "Number of children: " << root->children().size(); 21 | 22 | // Delete all children 23 | for (auto child : root->children()) { 24 | root->deleteChild(child->objectName()); 25 | } 26 | 27 | // Display number of children 28 | qDebug() << "Number of children: " << root->children().size(); 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /src/core/cpp/custom_signal_slots/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(custom_signals_and_slots 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(${PROJECT_NAME} 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET ${PROJECT_NAME} 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(${PROJECT_NAME} 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(${PROJECT_NAME} 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(${PROJECT_NAME} 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 | ) 54 | 55 | if(QT_VERSION_MAJOR EQUAL 6) 56 | qt_finalize_executable(${PROJECT_NAME}) 57 | endif() 58 | -------------------------------------------------------------------------------- /src/core/cpp/custom_signal_slots/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/core/cpp/custom_signal_slots/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent), ui(new Ui::MainWindow) { 6 | ui->setupUi(this); 7 | 8 | connect(ui->pushButton, &QPushButton::clicked, this, 9 | [=]() { emit sendString(ui->lineEdit->text()); }); 10 | 11 | connect(this, &MainWindow::sendString, this, &MainWindow::display); 12 | } 13 | 14 | void MainWindow::display(QString str) { ui->label->setText(str); } 15 | 16 | MainWindow::~MainWindow() { delete ui; } 17 | -------------------------------------------------------------------------------- /src/core/cpp/custom_signal_slots/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { 9 | class MainWindow; 10 | } 11 | QT_END_NAMESPACE 12 | 13 | class MainWindow : public QMainWindow { 14 | Q_OBJECT 15 | 16 | public: 17 | MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | signals: 20 | void sendString(QString); 21 | 22 | private slots: 23 | void display(QString); 24 | 25 | private: 26 | Ui::MainWindow *ui; 27 | }; 28 | #endif // MAINWINDOW_H 29 | -------------------------------------------------------------------------------- /src/core/cpp/qvariant_and_qmetatype/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(custom_type 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(${PROJECT_NAME} 18 | main.cpp 19 | custom_type.h 20 | custom_type.cpp 21 | ) 22 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 23 | -------------------------------------------------------------------------------- /src/core/cpp/qvariant_and_qmetatype/custom_type.cpp: -------------------------------------------------------------------------------- 1 | #include "custom_type.h" 2 | 3 | Person::Person() : name(""), age(0) {} 4 | 5 | Person::Person(const QString &name, int age) : name(name), age(age) {} 6 | 7 | Person::Person(const Person &other) : name(other.name), age(other.age) {} 8 | 9 | Person::~Person() {} 10 | -------------------------------------------------------------------------------- /src/core/cpp/qvariant_and_qmetatype/custom_type.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_CORE_QVARIANT_AND_QMETATYPE_CUSTOM_TYPE_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_CORE_QVARIANT_AND_QMETATYPE_CUSTOM_TYPE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Person { 9 | public: 10 | Person(); 11 | Person(const QString &name, int age); 12 | Person(const Person &other); 13 | ~Person(); 14 | 15 | QString name; 16 | int age; 17 | }; 18 | 19 | Q_DECLARE_METATYPE(Person) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /src/core/cpp/qvariant_and_qmetatype/main.cpp: -------------------------------------------------------------------------------- 1 | #include "custom_type.h" 2 | #include 3 | #include 4 | 5 | auto main(int /*argc*/, char * /*argv*/[]) -> int { 6 | 7 | QVariant variant = 0; 8 | variant = 42; 9 | qDebug() << variant.toInt(); 10 | 11 | variant = QString("Hello"); 12 | qDebug() << variant.toString(); 13 | 14 | variant = QVariant::fromValue(Person("John", 42)); 15 | qDebug() << variant.value().name; 16 | qDebug() << variant.value().age; 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /src/core/cpp/smart_pointers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(smart_pointers 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/core/python/custom_signal_slots/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from PyQt6 import QtWidgets, uic 4 | from PyQt6.QtCore import pyqtSignal, pyqtSlot 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | 9 | send_string = pyqtSignal(str) 10 | 11 | def __init__(self): 12 | super().__init__() 13 | uic.loadUi("main_window.ui", self) 14 | 15 | self.pushButton.clicked.connect( 16 | lambda: self.send_string.emit(self.lineEdit.text()) 17 | ) 18 | self.send_string.connect(lambda message: self.slot_display_string(message)) 19 | self.show() 20 | 21 | @pyqtSlot() 22 | def slot_display_string(self, message): 23 | self.label.setText(message) 24 | 25 | 26 | def main(): 27 | app = QtWidgets.QApplication(sys.argv) 28 | MainWindow() 29 | app.exec() 30 | 31 | 32 | if __name__ == "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /src/core/python/custom_signal_slots/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/files/cpp/file_info/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(file_info 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/files/cpp/file_info/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | void displaySubDirInfo(QDir rootDir) { 9 | qDebug() << "Following subdirs found in : " << rootDir.absolutePath(); 10 | auto dirs = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); 11 | 12 | for (auto &dir : dirs) { 13 | qDebug() << dir.fileName(); 14 | } 15 | } 16 | 17 | void displayChildFilesInfo(QDir rootDir) { 18 | qDebug() << "Following files found in : " << rootDir.absolutePath(); 19 | auto files = rootDir.entryInfoList(QDir::Files); 20 | 21 | for (auto &file : files) { 22 | qDebug() << "Name: " << file.fileName(); 23 | qDebug() << "Size: " << file.size(); 24 | qDebug() << "Created: " << file.birthTime(); 25 | qDebug() << "Modified: " << file.lastModified(); 26 | } 27 | } 28 | 29 | void displayFileInfo(QString path) { 30 | 31 | QDir rootDir(path); 32 | 33 | displaySubDirInfo(rootDir); 34 | displayChildFilesInfo(rootDir); 35 | } 36 | 37 | auto main(int argc, char *argv[]) -> int { 38 | 39 | // displayFileInfo(QDir::tempPath()); 40 | displayFileInfo(QDir::homePath()); 41 | } 42 | -------------------------------------------------------------------------------- /src/files/cpp/file_operations/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(file_operations 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/files/cpp/json_serialization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(json_serialization 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(${PROJECT_NAME} 18 | main.cpp 19 | json_serializable_interface.h 20 | player.h 21 | player.cpp 22 | ) 23 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 24 | -------------------------------------------------------------------------------- /src/files/cpp/json_serialization/json_serializable_interface.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_FILES_JSON_SERIALIZATION_JSON_SERIALIZABLE_INTERFACE_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_FILES_JSON_SERIALIZATION_JSON_SERIALIZABLE_INTERFACE_H 3 | 4 | #include 5 | 6 | class JsonSerializableInterface { 7 | public: 8 | virtual void toJson(QJsonObject &root) const = 0; 9 | virtual void fromJson(const QJsonObject &root) = 0; 10 | }; 11 | #endif 12 | -------------------------------------------------------------------------------- /src/files/cpp/json_serialization/main.cpp: -------------------------------------------------------------------------------- 1 | #include "player.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | auto main(int argc, char *argv[]) -> int { 8 | 9 | Player player("John", 100); 10 | QJsonObject root; 11 | player.toJson(root); 12 | qDebug() << root; 13 | 14 | QString path = "player.json"; 15 | QFile file(path); 16 | if (!file.open(QIODevice::WriteOnly)) { 17 | qDebug() << "Could not open file for writing"; 18 | return 1; 19 | } 20 | QJsonDocument doc(root); 21 | file.write(doc.toJson()); 22 | file.close(); 23 | 24 | // open file and read json 25 | if (!file.open(QIODevice::ReadOnly)) { 26 | qDebug() << "Could not open file for reading"; 27 | return 1; 28 | } 29 | 30 | QByteArray data = file.readAll(); 31 | QJsonDocument doc2 = QJsonDocument::fromJson(data); 32 | QJsonObject root2 = doc2.object(); 33 | file.close(); 34 | 35 | Player player2; 36 | player2.fromJson(root2); 37 | qDebug() << player2; 38 | qDebug() << (player == player2); 39 | 40 | // remove temp file 41 | QFile::remove(path); 42 | } 43 | -------------------------------------------------------------------------------- /src/files/cpp/json_serialization/player.cpp: -------------------------------------------------------------------------------- 1 | #include "player.h" 2 | 3 | Player::Player(QString name, int score) : name(name), score(score) {} 4 | 5 | Player::Player(const Player &other) : name(other.name), score(other.score) {} 6 | 7 | Player::Player() : name(""), score(0) {} 8 | 9 | auto Player::operator=(const Player &other) -> Player & { 10 | name = other.name; 11 | score = other.score; 12 | return *this; 13 | } 14 | 15 | Player::~Player() {} 16 | 17 | QString Player::getName() const { return name; } 18 | 19 | auto Player::getScore() const -> int { return score; } 20 | 21 | void Player::toJson(QJsonObject &root) const { 22 | root["name"] = name; 23 | root["score"] = score; 24 | } 25 | 26 | void Player::fromJson(const QJsonObject &root) { 27 | name = root["name"].toString(); 28 | score = root["score"].toInt(); 29 | } 30 | 31 | QDebug operator<<(QDebug dbg, const Player &player) { 32 | dbg.nospace() << "Player(" << player.name << ", " << player.score << ")"; 33 | return dbg.space(); 34 | } 35 | 36 | auto Player::operator==(const Player &other) const -> bool { 37 | return name == other.name && score == other.score; 38 | } -------------------------------------------------------------------------------- /src/files/cpp/json_serialization/player.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_FILES_JSON_SERIALIZATION_PLAYER_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_FILES_JSON_SERIALIZATION_PLAYER_H 3 | 4 | #include "json_serializable_interface.h" 5 | #include 6 | 7 | class Player : public JsonSerializableInterface { 8 | 9 | private: 10 | QString name; 11 | int score; 12 | 13 | public: 14 | Player(QString name, int score); 15 | Player(const Player &other); 16 | Player(); 17 | auto operator=(const Player &other) -> Player &; 18 | virtual ~Player(); 19 | 20 | QString getName() const; 21 | auto getScore() const -> int; 22 | 23 | virtual void toJson(QJsonObject &root) const; 24 | virtual void fromJson(const QJsonObject &root); 25 | 26 | auto operator==(const Player &other) const -> bool; 27 | friend QDebug operator<<(QDebug dbg, const Player &player); 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/files/cpp/storage_info/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(storage_info 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(${PROJECT_NAME} 18 | main.cpp 19 | ) 20 | target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/files/cpp/storage_info/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void displaySubDirInfo(QDir rootDir) { 8 | qDebug() << "Following subdirs found in : " << rootDir.absolutePath(); 9 | auto dirs = rootDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); 10 | 11 | for (auto &dir : dirs) { 12 | qDebug() << dir.fileName(); 13 | } 14 | } 15 | 16 | void displayStorageInfo(QStorageInfo storageInfo) { 17 | qDebug() << "Root: " << storageInfo.isRoot(); 18 | qDebug() << "Device: " << storageInfo.device(); 19 | qDebug() << "Name: " << storageInfo.displayName(); 20 | qDebug() << "Type: " << storageInfo.fileSystemType(); 21 | qDebug() << "Total space: " << storageInfo.bytesTotal() / 1024 / 1024 << "MB"; 22 | qDebug() << "Available space: " << storageInfo.bytesAvailable() / 1024 / 1024 23 | << "MB"; 24 | } 25 | 26 | auto main(int argc, char *argv[]) -> int { 27 | 28 | auto volumes = QStorageInfo::mountedVolumes(); 29 | for (auto &volume : volumes) { 30 | displayStorageInfo(volume); 31 | } 32 | 33 | auto root = QStorageInfo::root(); 34 | displaySubDirInfo(root.rootPath()); 35 | } 36 | -------------------------------------------------------------------------------- /src/files/python/file_info/main.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtCore 2 | 3 | 4 | def display_sub_dir_info(root_dir): 5 | print(f"Following subdirs found in : {root_dir.absolutePath()}") 6 | dirs = root_dir.entryInfoList( 7 | QtCore.QDir.Filter.Dirs | QtCore.QDir.Filter.NoDotAndDotDot 8 | ) 9 | for found_dir in dirs: 10 | print(found_dir.fileName()) 11 | 12 | 13 | def display_child_files_info(root_dir): 14 | print(f"Following files found in : {root_dir.absolutePath()}") 15 | files = root_dir.entryInfoList(QtCore.QDir.Filter.Files) 16 | for file in files: 17 | print(f"Name: {file.fileName()}") 18 | print(f"Size: {file.size() / 1024}KB") 19 | print(f"Created: {file.birthTime().toString()}") 20 | print(f"Modified: {file.lastModified().toString()}") 21 | 22 | 23 | def display_file_info(path): 24 | root_dir = QtCore.QDir(path) 25 | display_sub_dir_info(root_dir) 26 | display_child_files_info(root_dir) 27 | 28 | 29 | def main(): 30 | # display_file_info(QtCore.QDir.tempPath()) 31 | display_file_info(QtCore.QDir.homePath()) 32 | 33 | 34 | if __name__ == "__main__": 35 | main() 36 | -------------------------------------------------------------------------------- /src/files/python/file_info/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/files/python/file_operations/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/files/python/json_serialization/json_serializable_interface.py: -------------------------------------------------------------------------------- 1 | from abc import ABC, abstractmethod 2 | 3 | 4 | class JsonSerializableInterface(ABC): 5 | @abstractmethod 6 | def to_json(self, root) -> None: 7 | pass 8 | 9 | @abstractmethod 10 | def from_json(self, root) -> None: 11 | pass 12 | -------------------------------------------------------------------------------- /src/files/python/json_serialization/json_utils.py: -------------------------------------------------------------------------------- 1 | def dict_to_json(root, spaces=4): 2 | content = list() 3 | 4 | def value_to_json_format(value): 5 | if isinstance(value, str): 6 | return '"' + value + '"' 7 | elif isinstance(value, list): 8 | return "[" + ", ".join(value_to_json_format(v) for v in value) + "]" 9 | return str(value) 10 | 11 | def remove_trailing_commas(): 12 | if content[-1][-1] == ",": 13 | content[-1] = content[-1][:-1] 14 | 15 | def _dict_to_json_inner(root, level=1): 16 | for key, value in root.items(): 17 | if isinstance(value, dict): 18 | content.append("\n" + " " * level * spaces + '"' + key + '": {') 19 | _dict_to_json_inner(value, level + 1) 20 | remove_trailing_commas() 21 | content.append("\n" + " " * level * spaces + "},") 22 | else: 23 | content.append( 24 | f"{' ' * level * spaces}\"{key}\": {value_to_json_format(value)}," 25 | ) 26 | remove_trailing_commas() 27 | 28 | _dict_to_json_inner(root) 29 | return ["{"] + content + ["}"] 30 | -------------------------------------------------------------------------------- /src/files/python/json_serialization/main.py: -------------------------------------------------------------------------------- 1 | from json_utils import dict_to_json 2 | from player import Player 3 | from PyQt6 import QtCore 4 | 5 | 6 | def main(): 7 | player = Player("John", 100) 8 | root = dict() 9 | player.to_json(root) 10 | print(root) 11 | 12 | path = "player.json" 13 | file = QtCore.QFile(path) 14 | if not file.open( 15 | QtCore.QIODevice.OpenModeFlag.WriteOnly | QtCore.QIODevice.OpenModeFlag.Text 16 | ): 17 | print("Cannot create file") 18 | return 1 19 | text_stream = QtCore.QTextStream(file) 20 | for i, line in enumerate(dict_to_json(root)): 21 | text_stream << line + "\n" 22 | file.close() 23 | print("File created successfully") 24 | 25 | # open file and read json 26 | if not file.open(QtCore.QIODevice.OpenModeFlag.ReadOnly): 27 | print("Cannot open file for reading") 28 | return 1 29 | 30 | data = file.readAll() 31 | doc = QtCore.QJsonDocument.fromJson(data) 32 | root2 = doc.object() 33 | file.close() 34 | 35 | player2 = Player() 36 | player2.from_json(root2) 37 | print(player2) 38 | print(player == player2) 39 | 40 | # remove temp file 41 | QtCore.QFile.remove(path) 42 | 43 | 44 | if __name__ == "__main__": 45 | main() 46 | -------------------------------------------------------------------------------- /src/files/python/json_serialization/player.py: -------------------------------------------------------------------------------- 1 | from json_serializable_interface import JsonSerializableInterface 2 | 3 | 4 | class Player(JsonSerializableInterface): 5 | def __init__(self, name="", score=0): 6 | self.name = name 7 | self.score = score 8 | 9 | def to_json(self, root): 10 | root["name"] = self.name 11 | root["score"] = self.score 12 | 13 | def from_json(self, root): 14 | self.name = root["name"].toString() 15 | self.score = root["score"].toInt() 16 | 17 | def __eq__(self, other): 18 | return self.name == other.name and self.score == other.score 19 | 20 | def __str__(self): 21 | return "Player(" + self.name + ", " + str(self.score) + ")" 22 | 23 | def __repr__(self): 24 | return self.__str__() 25 | 26 | def __hash__(self): 27 | return hash(self.name) + hash(self.score) 28 | 29 | def __lt__(self, other): 30 | return self.score < other.score 31 | 32 | def __gt__(self, other): 33 | return self.score > other.score 34 | 35 | def __le__(self, other): 36 | return self.score <= other.score 37 | 38 | def __ge__(self, other): 39 | return self.score >= other.score 40 | 41 | def __ne__(self, other): 42 | return not (self == other) 43 | -------------------------------------------------------------------------------- /src/files/python/json_serialization/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/files/python/storage_info/main.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtCore 2 | 3 | 4 | def display_sub_dir_info(root_dir): 5 | root_dir = QtCore.QDir(root_dir) 6 | print(f"Following subdirs found in : {root_dir.absolutePath()}") 7 | dirs = root_dir.entryInfoList( 8 | QtCore.QDir.Filter.Dirs | QtCore.QDir.Filter.NoDotAndDotDot 9 | ) 10 | for found_dir in dirs: 11 | print(found_dir.fileName()) 12 | 13 | 14 | def display_storage_info(storage_info): 15 | print(f"Root: {storage_info.isRoot()}") 16 | print(f"Device: {storage_info.device()}") 17 | print(f"Name: {storage_info.displayName()}") 18 | print(f"Type: {storage_info.fileSystemType()}") 19 | print(f"Total space: {storage_info.bytesTotal() / 1024 / 1024}MB") 20 | print(f"Available space: {storage_info.bytesAvailable() / 1024 / 1024}MB") 21 | 22 | 23 | def main(): 24 | volumes = QtCore.QStorageInfo.mountedVolumes() 25 | for volume in volumes: 26 | display_storage_info(volume) 27 | 28 | root = QtCore.QStorageInfo.root() 29 | display_sub_dir_info(root.rootPath()) 30 | 31 | 32 | if __name__ == "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /src/files/python/storage_info/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/graphics/cpp/image_cropper/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(image_cropper 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | image_cropper.cpp 23 | image_cropper.h 24 | ) 25 | 26 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 27 | qt_add_executable(${PROJECT_NAME} 28 | MANUAL_FINALIZATION 29 | ${PROJECT_SOURCES} 30 | ) 31 | # Define target properties for Android with Qt 6 as: 32 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 33 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 34 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 35 | else() 36 | if(ANDROID) 37 | add_library(${PROJECT_NAME} SHARED 38 | ${PROJECT_SOURCES} 39 | ) 40 | # Define properties for Android with Qt 5 after find_package() calls as: 41 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 42 | else() 43 | add_executable(${PROJECT_NAME} 44 | ${PROJECT_SOURCES} 45 | ) 46 | endif() 47 | endif() 48 | 49 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 50 | 51 | set_target_properties(${PROJECT_NAME} PROPERTIES 52 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 53 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 54 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(${PROJECT_NAME}) 59 | endif() 60 | -------------------------------------------------------------------------------- /src/graphics/cpp/image_cropper/image_cropper.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_IMAGE_CROPPER_IMAGE_CROPPER_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_IMAGE_CROPPER_IMAGE_CROPPER_H 3 | 4 | #include 5 | 6 | class ImageCropper : public QWidget { 7 | Q_OBJECT 8 | public: 9 | explicit ImageCropper(QWidget *parent = nullptr); 10 | void setPixmapFromFile(QString fileName); 11 | 12 | signals: 13 | 14 | private: 15 | QPixmap pixmap; 16 | void paintEvent(QPaintEvent *event); 17 | void dropEvent(QDropEvent *event); 18 | void dragEnterEvent(QDragEnterEvent *event); 19 | void dragMoveEvent(QDragMoveEvent *event); 20 | }; 21 | 22 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_IMAGE_CROPPER_IMAGE_CROPPER_H 23 | -------------------------------------------------------------------------------- /src/graphics/cpp/image_cropper/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | auto main(int argc, char *argv[]) -> int { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/graphics/cpp/image_cropper/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "ui_main_window.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | MainWindow::MainWindow(QWidget *parent) 13 | : QMainWindow(parent), ui(new Ui::MainWindow) { 14 | ui->setupUi(this); 15 | } 16 | 17 | MainWindow::~MainWindow() { delete ui; } 18 | 19 | void MainWindow::on_actionSave_triggered() {} 20 | 21 | void MainWindow::on_actionOpen_triggered() { 22 | auto fileName = QFileDialog::getOpenFileName( 23 | this, tr("Open Image"), QDir::currentPath(), 24 | tr("Image Files (*.jpg *.JPG *.png *.PNG, *.bmp, *.BMP)")); 25 | 26 | ui->image_cropper->setPixmapFromFile(fileName); 27 | } 28 | -------------------------------------------------------------------------------- /src/graphics/cpp/image_cropper/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_IMAGE_CROPPER_MAIN_WINDOW_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_IMAGE_CROPPER_MAIN_WINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } // namespace Ui 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private slots: 20 | void on_actionSave_triggered(); 21 | void on_actionOpen_triggered(); 22 | 23 | private: 24 | Ui::MainWindow *ui; 25 | }; 26 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_IMAGE_CROPPER_MAIN_WINDOW_H 27 | -------------------------------------------------------------------------------- /src/graphics/cpp/image_cropper/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 0 31 | 0 32 | 800 33 | 20 34 | 35 | 36 | 37 | 38 | File 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Open 49 | 50 | 51 | 52 | 53 | Save 54 | 55 | 56 | 57 | 58 | 59 | ImageCropper 60 | QWidget 61 |
image_cropper.h
62 | 1 63 |
64 |
65 | 66 | 67 |
68 | -------------------------------------------------------------------------------- /src/graphics/cpp/movable_image/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(movable_image 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | movable_image.cpp 23 | movable_image.h 24 | ) 25 | 26 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 27 | qt_add_executable(${PROJECT_NAME} 28 | MANUAL_FINALIZATION 29 | ${PROJECT_SOURCES} 30 | ) 31 | # Define target properties for Android with Qt 6 as: 32 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 33 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 34 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 35 | else() 36 | if(ANDROID) 37 | add_library(${PROJECT_NAME} SHARED 38 | ${PROJECT_SOURCES} 39 | ) 40 | # Define properties for Android with Qt 5 after find_package() calls as: 41 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 42 | else() 43 | add_executable(${PROJECT_NAME} 44 | ${PROJECT_SOURCES} 45 | ) 46 | endif() 47 | endif() 48 | 49 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 50 | 51 | set_target_properties(${PROJECT_NAME} PROPERTIES 52 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 53 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 54 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(${PROJECT_NAME}) 59 | endif() 60 | -------------------------------------------------------------------------------- /src/graphics/cpp/movable_image/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include 3 | 4 | auto main(int argc, char *argv[]) -> int { 5 | QApplication a(argc, argv); 6 | MainWindow w; 7 | w.show(); 8 | return a.exec(); 9 | } 10 | -------------------------------------------------------------------------------- /src/graphics/cpp/movable_image/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "movable_image.h" 3 | #include "ui_main_window.h" 4 | 5 | MainWindow::MainWindow(QWidget *parent) 6 | : QMainWindow(parent), ui(new Ui::MainWindow) { 7 | ui->setupUi(this); 8 | scene = new QGraphicsScene(this); 9 | ui->graphicsView->setScene(scene); 10 | 11 | // set QSurfaceFormat for graphicsView 12 | 13 | auto text = scene->addText("Drop pictures here", QFont("Ubuntu", 20)); 14 | text->setFlag(QGraphicsItem::ItemIsMovable); 15 | text->setFlag(QGraphicsItem::ItemIsSelectable); 16 | } 17 | 18 | MainWindow::~MainWindow() { delete ui; } 19 | 20 | void MainWindow::on_addButton_released() { 21 | scene->addItem(new MovableImage(this)); 22 | } 23 | 24 | void MainWindow::on_removeButton_released() { 25 | for (auto item : scene->selectedItems()) { 26 | scene->removeItem(item); 27 | delete item; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/graphics/cpp/movable_image/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVABLE_IMAGE_MAIN_WINDOW_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVABLE_IMAGE_MAIN_WINDOW_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { 9 | class MainWindow; 10 | } // namespace Ui 11 | QT_END_NAMESPACE 12 | 13 | class MainWindow : public QMainWindow { 14 | Q_OBJECT 15 | 16 | public: 17 | MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | 20 | private slots: 21 | void on_addButton_released(); 22 | void on_removeButton_released(); 23 | 24 | private: 25 | Ui::MainWindow *ui; 26 | QGraphicsScene *scene; 27 | }; 28 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVABLE_IMAGE_MAIN_WINDOW_H 29 | -------------------------------------------------------------------------------- /src/graphics/cpp/movable_image/movable_image.cpp: -------------------------------------------------------------------------------- 1 | #include "movable_image.h" 2 | #include 3 | 4 | const int rectSize = 100; 5 | 6 | MovableImage::MovableImage(QObject *parent) : QObject(parent), QGraphicsItem() { 7 | 8 | this->setFlag(QGraphicsItem::ItemIsMovable); 9 | this->setFlag(QGraphicsItem::ItemIsSelectable); 10 | this->setFlag(QGraphicsItem::ItemSendsScenePositionChanges); 11 | } 12 | 13 | QRectF MovableImage::boundingRect() const { 14 | return QRectF(-rectSize / 2, -rectSize / 2, rectSize, rectSize); 15 | } 16 | 17 | void MovableImage::paint(QPainter *painter, 18 | const QStyleOptionGraphicsItem *option, 19 | QWidget *widget) { 20 | Q_UNUSED(option); 21 | Q_UNUSED(widget); 22 | 23 | auto brushColor = isSelected() ? Qt::darkBlue : Qt::darkGray; 24 | painter->setPen(Qt::black); 25 | painter->setBrush(brushColor); 26 | painter->drawRect(-rectSize / 2, -rectSize / 2, rectSize, rectSize); 27 | } 28 | -------------------------------------------------------------------------------- /src/graphics/cpp/movable_image/movable_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVABLE_IMAGE_MOVABLE_IMAGE_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVABLE_IMAGE_MOVABLE_IMAGE_H 3 | 4 | #include 5 | 6 | class MovableImage : public QObject, public QGraphicsItem { 7 | Q_OBJECT 8 | public: 9 | MovableImage(QObject *parent); 10 | 11 | private: 12 | QRectF boundingRect() const; 13 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 14 | QWidget *widget); 15 | }; 16 | 17 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVABLE_IMAGE_MOVABLE_IMAGE_H 18 | -------------------------------------------------------------------------------- /src/graphics/cpp/moving_balls/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(moving_balls 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | movable_image.cpp 23 | movable_image.h 24 | bordered_scene.cpp 25 | bordered_scene.h 26 | ) 27 | 28 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 29 | qt_add_executable(${PROJECT_NAME} 30 | MANUAL_FINALIZATION 31 | ${PROJECT_SOURCES} 32 | ) 33 | # Define target properties for Android with Qt 6 as: 34 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 35 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 36 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 37 | else() 38 | if(ANDROID) 39 | add_library(${PROJECT_NAME} SHARED 40 | ${PROJECT_SOURCES} 41 | ) 42 | # Define properties for Android with Qt 5 after find_package() calls as: 43 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 44 | else() 45 | add_executable(${PROJECT_NAME} 46 | ${PROJECT_SOURCES} 47 | ) 48 | endif() 49 | endif() 50 | 51 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 52 | 53 | set_target_properties(${PROJECT_NAME} PROPERTIES 54 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 55 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 56 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 57 | ) 58 | 59 | if(QT_VERSION_MAJOR EQUAL 6) 60 | qt_finalize_executable(${PROJECT_NAME}) 61 | endif() 62 | -------------------------------------------------------------------------------- /src/graphics/cpp/moving_balls/bordered_scene.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_BORDERED_SCENE_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_BORDERED_SCENE_H 3 | 4 | #include 5 | 6 | class BorderedScene : public QGraphicsScene { 7 | public: 8 | explicit BorderedScene(QRectF borderRect, unsigned int numBalls = 10, 9 | QObject *parent = nullptr); 10 | 11 | public slots: 12 | void advance(); 13 | 14 | private: 15 | void drawSceneBorder(); 16 | }; 17 | 18 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_BORDERED_SCENE_H 19 | -------------------------------------------------------------------------------- /src/graphics/cpp/moving_balls/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include 3 | 4 | auto main(int argc, char *argv[]) -> int { 5 | QApplication a(argc, argv); 6 | 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/graphics/cpp/moving_balls/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "movable_image.h" 3 | #include "ui_main_window.h" 4 | 5 | MainWindow::MainWindow(QWidget *parent) 6 | : QMainWindow(parent), ui(new Ui::MainWindow) { 7 | ui->setupUi(this); 8 | scene = new BorderedScene(QRectF(0, 0, 300, 300), 10, this); 9 | ui->graphicsView->setScene(scene); 10 | 11 | timer = new QTimer(this); 12 | connect(timer, &QTimer::timeout, scene, &BorderedScene::advance); 13 | timer->start(100); 14 | } 15 | 16 | MainWindow::~MainWindow() { delete ui; } 17 | 18 | void MainWindow::on_addButton_released() { 19 | scene->addItem(new MovableImage(scene->sceneRect(), this)); 20 | } 21 | 22 | void MainWindow::on_removeButton_released() { 23 | for (auto item : scene->selectedItems()) { 24 | scene->removeItem(item); 25 | delete item; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/graphics/cpp/moving_balls/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_MAIN_WINDOW_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_MAIN_WINDOW_H 3 | 4 | #include "bordered_scene.h" 5 | #include 6 | #include 7 | #include 8 | 9 | QT_BEGIN_NAMESPACE 10 | namespace Ui { 11 | class MainWindow; 12 | } // namespace Ui 13 | QT_END_NAMESPACE 14 | 15 | class MainWindow : public QMainWindow { 16 | Q_OBJECT 17 | 18 | public: 19 | MainWindow(QWidget *parent = nullptr); 20 | ~MainWindow(); 21 | 22 | private slots: 23 | void on_addButton_released(); 24 | void on_removeButton_released(); 25 | 26 | private: 27 | Ui::MainWindow *ui; 28 | BorderedScene *scene; 29 | QTimer *timer; 30 | }; 31 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_MAIN_WINDOW_H 32 | -------------------------------------------------------------------------------- /src/graphics/cpp/moving_balls/movable_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_MOVABLE_IMAGE_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_MOVABLE_IMAGE_H 3 | 4 | #include 5 | 6 | class MovableImage : public QObject, public QGraphicsItem { 7 | Q_OBJECT 8 | public: 9 | MovableImage(QRectF rectBorder, QObject *parent); 10 | QRectF boundingRect() const; 11 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, 12 | QWidget *widget); 13 | QPointF getSpeed(); 14 | void setSpeed(QPointF point); 15 | void reverseSpeed(); 16 | 17 | protected: 18 | void advance(int phase); 19 | 20 | private: 21 | QPointF speed; 22 | void collideWithWall(); 23 | }; 24 | 25 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_MOVING_BALLS_MOVABLE_IMAGE_H 26 | -------------------------------------------------------------------------------- /src/graphics/cpp/transformations/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(transformation_display 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | transformation_display.cpp 23 | transformation_display.h 24 | ) 25 | 26 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 27 | qt_add_executable(${PROJECT_NAME} 28 | MANUAL_FINALIZATION 29 | ${PROJECT_SOURCES} 30 | ) 31 | # Define target properties for Android with Qt 6 as: 32 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 33 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 34 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 35 | else() 36 | if(ANDROID) 37 | add_library(${PROJECT_NAME} SHARED 38 | ${PROJECT_SOURCES} 39 | ) 40 | # Define properties for Android with Qt 5 after find_package() calls as: 41 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 42 | else() 43 | add_executable(${PROJECT_NAME} 44 | ${PROJECT_SOURCES} 45 | ) 46 | endif() 47 | endif() 48 | 49 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 50 | 51 | set_target_properties(${PROJECT_NAME} PROPERTIES 52 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 53 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 54 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(${PROJECT_NAME}) 59 | endif() 60 | -------------------------------------------------------------------------------- /src/graphics/cpp/transformations/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | auto main(int argc, char *argv[]) -> int { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/graphics/cpp/transformations/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent), ui(new Ui::MainWindow) { 6 | ui->setupUi(this); 7 | 8 | ui->xSpinBox->setValue(ui->transformationDisplay->getTranslate().x()); 9 | ui->ySpinBox->setValue(ui->transformationDisplay->getTranslate().y()); 10 | ui->scaleSpinBox->setValue(ui->transformationDisplay->getScale() * 100); 11 | ui->rotateSpinBox->setValue(ui->transformationDisplay->getRotate()); 12 | 13 | // conect ui->transformationDisplay setTranslate() to xSpinBox and ySpinBox 14 | connect(ui->xSpinBox, &QSpinBox::valueChanged, ui->transformationDisplay, 15 | [&](int x) { 16 | ui->transformationDisplay->setTranslate( 17 | x, ui->transformationDisplay->getTranslate().y()); 18 | }); 19 | 20 | connect(ui->ySpinBox, &QSpinBox::valueChanged, ui->transformationDisplay, 21 | [&](int y) { 22 | ui->transformationDisplay->setTranslate( 23 | ui->transformationDisplay->getTranslate().x(), y); 24 | }); 25 | 26 | // conect ui->transformationDisplay setScale() to scaleSpinBox 27 | connect(ui->scaleSpinBox, &QDoubleSpinBox::valueChanged, 28 | ui->transformationDisplay, [&](double scale) { 29 | ui->transformationDisplay->setScale(scale / 100); 30 | }); 31 | 32 | // conect ui->transformationDisplay setRotate() to rotateSpinBox 33 | connect(ui->rotateSpinBox, &QSpinBox::valueChanged, ui->transformationDisplay, 34 | [&](int angle) { ui->transformationDisplay->setRotate(angle); }); 35 | } 36 | 37 | MainWindow::~MainWindow() { delete ui; } 38 | -------------------------------------------------------------------------------- /src/graphics/cpp/transformations/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_TRANSFORMATIONS_MAIN_WINDOW_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_TRANSFORMATIONS_MAIN_WINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } // namespace Ui 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_TRANSFORMATIONS_MAIN_WINDOW_H 23 | -------------------------------------------------------------------------------- /src/graphics/cpp/transformations/transformation_display.cpp: -------------------------------------------------------------------------------- 1 | #include "transformation_display.h" 2 | #include 3 | 4 | TransformationDisplay::TransformationDisplay(QWidget *parent) 5 | : QWidget(parent), translation(0, 0), rotation(0), scale(1) {} 6 | 7 | TransformationDisplay::~TransformationDisplay() {} 8 | 9 | void TransformationDisplay::setTranslate(int x, int y) { 10 | translation.setX(x); 11 | translation.setY(y); 12 | update(); 13 | } 14 | 15 | void TransformationDisplay::setScale(float scale) { 16 | this->scale = scale; 17 | update(); 18 | } 19 | 20 | void TransformationDisplay::setRotate(float angle) { 21 | rotation = angle; 22 | update(); 23 | } 24 | 25 | QPoint TransformationDisplay::getTranslate() { return translation; } 26 | 27 | auto TransformationDisplay::getScale() const -> float { return scale; } 28 | 29 | auto TransformationDisplay::getRotate() const -> float { return rotation; } 30 | 31 | void TransformationDisplay::paintEvent(QPaintEvent * /*e*/) { 32 | QPainter painter(this); 33 | 34 | // apply transformations 35 | painter.translate(translation); 36 | painter.rotate(rotation); 37 | painter.scale(scale, scale); 38 | 39 | // set font size to heigth of widget / 3 40 | painter.setFont(QFont("Arial", this->height() / 3)); 41 | 42 | // Draw Qt text in the center of the widget 43 | // Make sure the whole text is visible 44 | painter.drawText(rect(), Qt::AlignCenter, "Qt"); 45 | } 46 | 47 | QSize TransformationDisplay::sizeHint() const { 48 | if (width() < 20 || height() < 20) 49 | return QSize(20, 20); 50 | 51 | return QSize(width(), height()); 52 | } 53 | -------------------------------------------------------------------------------- /src/graphics/cpp/transformations/transformation_display.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_TRANSFORMATIONS_TRANSFORMATION_DISPLAY_H 2 | #define _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_TRANSFORMATIONS_TRANSFORMATION_DISPLAY_H 3 | 4 | #include 5 | 6 | class TransformationDisplay : public QWidget { 7 | Q_OBJECT 8 | public: 9 | explicit TransformationDisplay(QWidget *parent = nullptr); 10 | ~TransformationDisplay(); 11 | void setTranslate(int x, int y); 12 | void setScale(float scale); 13 | void setRotate(float angle); 14 | QPoint getTranslate(); 15 | auto getScale() const -> float; 16 | auto getRotate() const -> float; 17 | 18 | protected: 19 | QSize sizeHint() const override; 20 | void paintEvent(QPaintEvent *e); 21 | 22 | private: 23 | QPoint translation; 24 | float rotation; 25 | float scale; 26 | }; 27 | 28 | #endif // _HOME_ADAM_QT_WIDGETS_SRC_GRAPHICS_TRANSFORMATIONS_TRANSFORMATION_DISPLAY_H 29 | -------------------------------------------------------------------------------- /src/graphics/python/image_cropper/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/graphics/python/image_cropper/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | from PyQt6.QtCore import QDir 3 | 4 | 5 | class MainWindow(QtWidgets.QMainWindow): 6 | def __init__(self): 7 | super().__init__() 8 | uic.loadUi("main_window.ui", self) 9 | self.show() 10 | 11 | def on_actionSave_triggered(self): 12 | pass 13 | 14 | def on_actionOpen_triggered(self): 15 | file_name = QtWidgets.QFileDialog.getOpenFileName( 16 | self, 17 | "Open Image", 18 | QDir.currentPath(), 19 | "Image Files (*.jpg *.JPG *.png *.PNG, *.bmp, *.BMP)", 20 | ) 21 | self.image_cropper.set_pixmap_from_file(file_name) 22 | -------------------------------------------------------------------------------- /src/graphics/python/image_cropper/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 0 31 | 0 32 | 800 33 | 20 34 | 35 | 36 | 37 | 38 | File 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | Open 49 | 50 | 51 | 52 | 53 | Save 54 | 55 | 56 | 57 | 58 | 59 | ImageCropper 60 | QWidget 61 |
image_cropper.h
62 | 1 63 |
64 |
65 | 66 | 67 |
68 | -------------------------------------------------------------------------------- /src/graphics/python/image_cropper/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/graphics/python/movable_image/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/graphics/python/movable_image/main_window.py: -------------------------------------------------------------------------------- 1 | from movable_image import MovableImage 2 | from PyQt6 import QtGui, QtWidgets, uic 3 | from PyQt6.QtWidgets import QGraphicsItem 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | self.scene = QtWidgets.QGraphicsScene(self) 11 | self.graphicsView.setScene(self.scene) 12 | text = self.scene.addText("Drop pictures here", QtGui.QFont("Ubuntu", 20)) 13 | text.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable) 14 | text.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable) 15 | self.show() 16 | 17 | def on_addButton_released(self): 18 | new_item = MovableImage(self) 19 | self.scene.addItem(new_item) 20 | 21 | def on_removeButton_released(self): 22 | for item in self.scene.selectedItems(): 23 | self.scene.removeItem(item) 24 | del item 25 | -------------------------------------------------------------------------------- /src/graphics/python/movable_image/movable_image.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtGui 2 | from PyQt6.QtCore import QObject, QRectF 3 | from PyQt6.QtGui import QColor, QPen 4 | from PyQt6.QtWidgets import QGraphicsItem 5 | 6 | rect_size = 100 7 | 8 | 9 | class MovableImage(QGraphicsItem, QObject): 10 | def __init__(self, parent=None): 11 | super(QGraphicsItem, self).__init__() 12 | # super(QObject, self).__init__(parent) 13 | self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable) 14 | self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable) 15 | self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemSendsScenePositionChanges) 16 | 17 | def boundingRect(self): 18 | return QRectF(-rect_size / 2, -rect_size / 2, rect_size, rect_size) 19 | 20 | def paint(self, painter, option, widget): 21 | brush_color = ( 22 | self.isSelected() 23 | and QtGui.QColorConstants.DarkGreen 24 | or QtGui.QColorConstants.DarkGray 25 | ) 26 | painter.setPen(QPen(QColor("black"))) 27 | painter.setBrush(brush_color) 28 | painter.drawRect(-rect_size / 2, -rect_size / 2, rect_size, rect_size) 29 | -------------------------------------------------------------------------------- /src/graphics/python/movable_image/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/graphics/python/moving_balls/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/graphics/python/moving_balls/main_window.py: -------------------------------------------------------------------------------- 1 | from bordered_scene import BorderedScene 2 | from movable_image import MovableImage 3 | from PyQt6 import QtCore, QtWidgets, uic 4 | from PyQt6.QtCore import QRectF 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | uic.loadUi("main_window.ui", self) 11 | self.scene = BorderedScene(QRectF(0, 0, 300, 300), 10, self) 12 | self.graphicsView.setScene(self.scene) 13 | 14 | timer = QtCore.QTimer(self) 15 | timer.timeout.connect(self.scene.advance) 16 | timer.start(100) 17 | 18 | self.show() 19 | 20 | def on_addButton_released(self): 21 | self.scene.addItem(MovableImage(self.scene.sceneRect(), self)) 22 | 23 | def on_removeButton_released(self): 24 | for item in self.scene.selectedItems(): 25 | self.scene.removeItem(item) 26 | del item 27 | -------------------------------------------------------------------------------- /src/graphics/python/moving_balls/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/graphics/python/transformations/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/graphics/python/transformations/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | from PyQt6.QtCore import QPoint 3 | 4 | 5 | class MainWindow(QtWidgets.QMainWindow): 6 | def __init__(self): 7 | super().__init__() 8 | uic.loadUi("main_window.ui", self) 9 | self.xSpinBox.setValue(self.transformationDisplay.translate.x()) 10 | self.ySpinBox.setValue(self.transformationDisplay.translate.y()) 11 | self.scaleSpinBox.setValue(self.transformationDisplay.scale * 100) 12 | self.rotateSpinBox.setValue(self.transformationDisplay.rotate) 13 | 14 | # connect ui->transformationDisplay setTranslate() to xSpinBox and 15 | # ySpinBox 16 | self.xSpinBox.valueChanged.connect( 17 | lambda x: self.transformationDisplay.update_translate( 18 | QPoint(x, self.transformationDisplay.translate.y()) 19 | ) 20 | ) 21 | self.ySpinBox.valueChanged.connect( 22 | lambda y: self.transformationDisplay.update_translate( 23 | QPoint(self.transformationDisplay.translate.x(), y) 24 | ) 25 | ) 26 | self.scaleSpinBox.valueChanged.connect( 27 | lambda scale: self.transformationDisplay.update_scale(scale / 100) 28 | ) 29 | self.rotateSpinBox.valueChanged.connect( 30 | lambda angle: self.transformationDisplay.update_rotate(angle) 31 | ) 32 | 33 | self.show() 34 | -------------------------------------------------------------------------------- /src/graphics/python/transformations/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/graphics/python/transformations/transformation_display.py: -------------------------------------------------------------------------------- 1 | from PyQt6.QtCore import QPoint, QSize, Qt 2 | from PyQt6.QtGui import QFont, QPainter, QPixmap 3 | from PyQt6.QtWidgets import QWidget 4 | 5 | 6 | class TransformationDisplay(QWidget): 7 | def __init__(self, parent=None): 8 | super(TransformationDisplay, self).__init__(parent) 9 | self._translation = QPoint(0, 0) 10 | self._rotation = 0 11 | self._scale = 1 12 | self.pixmap = QPixmap() 13 | 14 | @property 15 | def translate(self): 16 | return self._translation 17 | 18 | @translate.setter 19 | def translate(self, point): 20 | self._translation = point 21 | self.update() 22 | 23 | def update_translate(self, point): 24 | self.translate = point 25 | 26 | @property 27 | def scale(self): 28 | return self._scale 29 | 30 | @scale.setter 31 | def scale(self, scale): 32 | self._scale = scale 33 | self.update() 34 | 35 | def update_scale(self, scale): 36 | self.scale = scale 37 | 38 | @property 39 | def rotate(self): 40 | return self._rotation 41 | 42 | @rotate.setter 43 | def rotate(self, angle): 44 | self._rotation = angle 45 | self.update() 46 | 47 | def update_rotate(self, angle): 48 | self.rotate = angle 49 | 50 | def paintEvent(self, event): 51 | painter = QPainter(self) 52 | painter.translate(self._translation) 53 | painter.rotate(self._rotation) 54 | painter.scale(self._scale, self._scale) 55 | 56 | # set font size to height of widget / 3 57 | painter.setFont(QFont("Arial", self.height() / 3)) 58 | 59 | # Draw Qt text in the center of the widget 60 | # Make sure the whole text is visible 61 | painter.drawText(self.rect(), Qt.AlignmentFlag.AlignCenter, "Qt") 62 | 63 | def sizeHint(self): 64 | if self.width() < 20 or self.height() < 20: 65 | return QSize(20, 20) 66 | return QSize(self.width(), self.height()) 67 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/crypto_ranking_data.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct CryptoRankingData { 4 | QString name; 5 | QString iconPath; 6 | float price; 7 | float changePercent; 8 | float volume; 9 | float marketCap; 10 | }; 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/crypto_ranking_delegate.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CUSTOM_DELEGATE_H 3 | #define CUSTOM_DELEGATE_H 4 | 5 | #include 6 | 7 | class CryptoRankingDelegate : public QStyledItemDelegate { 8 | Q_OBJECT 9 | 10 | public: 11 | CryptoRankingDelegate(QObject *parent = nullptr); 12 | ~CryptoRankingDelegate(); 13 | 14 | void paint(QPainter *painter, const QStyleOptionViewItem &option, 15 | const QModelIndex &index) const; 16 | QSize sizeHint(const QStyleOptionViewItem &option, 17 | const QModelIndex &index) const; 18 | }; 19 | 20 | #endif // CUSTOM_DELEGATE_H 21 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/crypto_ranking_table.h: -------------------------------------------------------------------------------- 1 | #include "crypto_ranking_data.h" 2 | #include 3 | 4 | class CryptoRankingModel : public QAbstractTableModel { 5 | Q_OBJECT 6 | 7 | public: 8 | CryptoRankingModel(QObject *parent = 0); 9 | CryptoRankingModel(const QList &data, QObject *parent = 0); 10 | int rowCount(const QModelIndex &parent = QModelIndex()) const; 11 | int columnCount(const QModelIndex &parent = QModelIndex()) const; 12 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 13 | QVariant headerData(int section, Qt::Orientation orientation, 14 | int role = Qt::DisplayRole) const; 15 | void setData(const CryptoRankingData &data); 16 | void setData(const QList &data); 17 | void clear(); 18 | 19 | private: 20 | QList modelData; 21 | }; 22 | 23 | class CryptoRankingTable : public QTableView { 24 | Q_OBJECT 25 | 26 | public: 27 | CryptoRankingTable(QWidget *parent = 0); 28 | ~CryptoRankingTable(); 29 | void setModel(CryptoRankingModel *model); 30 | CryptoRankingModel *getModel(); 31 | }; 32 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/bitcoin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/bitcoin.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/bitcoin_cash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/bitcoin_cash.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/down.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/ethereum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/ethereum.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/litecoin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/litecoin.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/ripple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/ripple.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/crypto_ranking/images/up.png -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include 4 | #include 5 | 6 | MainWindow::MainWindow(QWidget *parent) 7 | : QMainWindow(parent), ui(new Ui::MainWindow) { 8 | ui->setupUi(this); 9 | 10 | auto model = new CryptoRankingModel(this); 11 | QList data; 12 | data.append(CryptoRankingData{"Bitcoin", "images/bitcoin.png", 8100.0, 11.56, 13 | 210123282., 361739253420.}); 14 | data.append(CryptoRankingData{"Ethereum", "images/ethereum.png", 730.0, 15 | -10.79, 76231423., 119951889218.}); 16 | data.append(CryptoRankingData{"Ripple", "images/ripple.png", 1.0, 382.23, 17 | 3241541123., 14866729546.}); 18 | data.append(CryptoRankingData{"Litecoin", "images/litecoin.png", 100.0, -0.23, 19 | 54256561134144., 3169548426.}); 20 | data.append(CryptoRankingData{"Bitcoin Cash", "images/bitcoin_cash.png", 21 | 800.0, -99.9921, 4532452, 225250788.}); 22 | model->setData(data); 23 | ui->tableView->setModel(model); 24 | } 25 | 26 | MainWindow::~MainWindow() { delete ui; } 27 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/crypto_ranking/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | QAbstractScrollArea::AdjustToContents 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 0 31 | 0 32 | 800 33 | 20 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | CryptoRankingTable 42 | QTableView 43 |
crypto_ranking_table.h
44 |
45 |
46 | 47 | 48 |
49 | -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/emoji_picker_data.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct EmojiData { 5 | QString name; 6 | QString iconPath; 7 | QList tags; 8 | 9 | EmojiData(const QString &name, const QString &iconPath, 10 | const QList &tags) 11 | : name(name), iconPath(iconPath), tags(tags) {} 12 | }; 13 | 14 | struct EmojiCategory { 15 | QString name; 16 | QList emojis; 17 | 18 | EmojiCategory(const QString &name, const QList &emojis) 19 | : name(name), emojis(emojis) {} 20 | }; -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/emoji_picker_delegate.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CUSTOM_DELEGATE_H 3 | #define CUSTOM_DELEGATE_H 4 | 5 | #include 6 | 7 | class EmojiPickerDelegate : public QStyledItemDelegate { 8 | Q_OBJECT 9 | 10 | public: 11 | EmojiPickerDelegate(QObject *parent = nullptr); 12 | ~EmojiPickerDelegate(); 13 | 14 | void paint(QPainter *painter, const QStyleOptionViewItem &option, 15 | const QModelIndex &index) const; 16 | QSize sizeHint(const QStyleOptionViewItem &option, 17 | const QModelIndex &index) const; 18 | }; 19 | 20 | #endif // CUSTOM_DELEGATE_H 21 | -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/emoji_picker_tree.h: -------------------------------------------------------------------------------- 1 | #include "emoji_picker_data.h" 2 | #include 3 | #include 4 | #include 5 | 6 | class EmojiPickerItem : public QStandardItem { 7 | public: 8 | EmojiPickerItem(const EmojiCategory &category, int columnCount); 9 | void setCategory(const EmojiCategory &category); 10 | void setColumnCount(int count); 11 | const EmojiCategory &category() const; 12 | EmojiCategory itemCategory; 13 | }; 14 | 15 | class EmojiPickerModel : public QStandardItemModel { 16 | Q_OBJECT 17 | 18 | public: 19 | EmojiPickerModel(QObject *parent = nullptr); 20 | ~EmojiPickerModel(); 21 | void appendRow(const EmojiCategory &category); 22 | void appendRow(const QList &categories); 23 | void clear(); 24 | void setColumnCount(int count); 25 | }; 26 | 27 | class EmojiPickerTree : public QTreeView { 28 | Q_OBJECT 29 | 30 | public: 31 | EmojiPickerTree(QWidget *parent = nullptr); 32 | ~EmojiPickerTree(); 33 | void setModel(EmojiPickerModel *model); 34 | EmojiPickerModel *model(); 35 | }; 36 | -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/boredom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/boredom.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/crying.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/crying.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/emoji.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/happy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/happy.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/hearts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/hearts.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/in_love.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/in_love.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/laugh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/laugh.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/love.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/love.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/nerd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/nerd.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/party.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/party.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/shame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/shame.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/sleeping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/sleeping.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/smile.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/star.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/thinking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/thinking.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/images/upside_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/cpp/emoji_picker/images/upside_down.png -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include 4 | #include 5 | #include 6 | 7 | MainWindow::MainWindow(QWidget *parent) 8 | : QMainWindow(parent), ui(new Ui::MainWindow) { 9 | ui->setupUi(this); 10 | 11 | auto model = new EmojiPickerModel(this); 12 | 13 | QStringList iconPaths; 14 | 15 | // find all paths in images folder 16 | QDir dir("images"); 17 | QFileInfoList fileInfoList = dir.entryInfoList(QDir::Files); 18 | for (auto fileInfo : fileInfoList) { 19 | iconPaths.append(fileInfo.absoluteFilePath()); 20 | } 21 | QList emojis; 22 | 23 | for (const auto &iconPath : iconPaths) { 24 | emojis.append(EmojiData(iconPath, iconPath, QList())); 25 | } 26 | 27 | EmojiCategory category = EmojiCategory("Category A", emojis); 28 | model->setColumnCount(7); 29 | model->appendRow(category); 30 | category.name = "Category B"; 31 | model->appendRow(category); 32 | 33 | ui->treeView->setModel(model); 34 | } 35 | 36 | MainWindow::~MainWindow() { delete ui; } 37 | -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/emoji_picker/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | EmojiPickerTree 38 | QTreeView 39 |
emoji_picker_tree.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/cpp/file_directory_treeview/clickable_tree_view.h: -------------------------------------------------------------------------------- 1 | #include "file_dir_model.h" 2 | #include 3 | 4 | class ClickableTreeView : public QTreeView { 5 | Q_OBJECT 6 | 7 | public: 8 | ClickableTreeView(QWidget *parent = nullptr); 9 | ~ClickableTreeView(); 10 | void setModel(FileDirModel *model); 11 | FileDirModel *model() const; 12 | bool mkdir(const QModelIndex &index, const QString &name); 13 | bool touch(const QModelIndex &index, const QString &name); 14 | bool pasteSelected(const QModelIndex &index); 15 | void startCopy(const QModelIndex &sourceIndex); 16 | void startCut(const QModelIndex &sourceIndex); 17 | void removeSelectedIndexes(); 18 | 19 | private: 20 | void startDrag(Qt::DropActions supportedActions); 21 | void dropEvent(QDropEvent *event); 22 | QModelIndex dragIndex; 23 | QModelIndex dropIndex; 24 | QModelIndex previouslySelected; 25 | QString selectedPath; 26 | void setupContextMenu(const QPoint &pos); 27 | void keyPressEvent(QKeyEvent *event); 28 | }; 29 | -------------------------------------------------------------------------------- /src/mvc/cpp/file_directory_treeview/file_dir_model.h: -------------------------------------------------------------------------------- 1 | #ifndef TREEMODEL_H 2 | #define TREEMODEL_H 3 | #include 4 | 5 | class FileDirModel : public QFileSystemModel { 6 | Q_OBJECT 7 | 8 | public: 9 | FileDirModel(QObject *parent = 0); 10 | ~FileDirModel(); 11 | void setRootPath(const QString &path); 12 | QModelIndex mkdir(const QModelIndex &parent, const QString &name); 13 | bool touch(const QModelIndex &index, const QString &name); 14 | bool paste(const QModelIndex &index, const QString &path); 15 | bool appendToDestination(QModelIndex sourceIndex, 16 | QModelIndex destinationIndex); 17 | 18 | private: 19 | QModelIndex firstDirAncestor(const QModelIndex &index); 20 | static QString getUniqueName(const QString &dirPath, const QString &name); 21 | static bool copyFile(const QString &sourcePath, const QString &destPath); 22 | static bool copyDirectory(const QString &sourcePath, const QString &destPath); 23 | }; 24 | #endif // TREEMODEL_H 25 | -------------------------------------------------------------------------------- /src/mvc/cpp/file_directory_treeview/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/file_directory_treeview/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include "file_dir_model.h" 4 | 5 | MainWindow::MainWindow(QWidget *parent) 6 | : QMainWindow(parent), ui(new Ui::MainWindow) { 7 | ui->setupUi(this); 8 | 9 | // set model 10 | auto model = new FileDirModel(this); 11 | model->setRootPath(QDir::currentPath()); 12 | ui->treeView->setModel(model); 13 | } 14 | 15 | MainWindow::~MainWindow() { delete ui; } 16 | -------------------------------------------------------------------------------- /src/mvc/cpp/file_directory_treeview/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/file_directory_treeview/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ClickableTreeView 38 | QTreeView 39 |
clickable_tree_view.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/cpp/item_delegate/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(custom_delegate 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | custom_delegate.cpp 23 | custom_delegate.h 24 | ) 25 | 26 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 27 | qt_add_executable(${PROJECT_NAME} 28 | MANUAL_FINALIZATION 29 | ${PROJECT_SOURCES} 30 | ) 31 | # Define target properties for Android with Qt 6 as: 32 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 33 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 34 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 35 | else() 36 | if(ANDROID) 37 | add_library(${PROJECT_NAME} SHARED 38 | ${PROJECT_SOURCES} 39 | ) 40 | # Define properties for Android with Qt 5 after find_package() calls as: 41 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 42 | else() 43 | add_executable(${PROJECT_NAME} 44 | ${PROJECT_SOURCES} 45 | ) 46 | endif() 47 | endif() 48 | 49 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 50 | 51 | set_target_properties(${PROJECT_NAME} PROPERTIES 52 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 53 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 54 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(${PROJECT_NAME}) 59 | endif() 60 | -------------------------------------------------------------------------------- /src/mvc/cpp/item_delegate/custom_delegate.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef CUSTOM_DELEGATE_H 3 | #define CUSTOM_DELEGATE_H 4 | 5 | #include 6 | 7 | class CustomDelegate : public QStyledItemDelegate { 8 | Q_OBJECT 9 | 10 | public: 11 | CustomDelegate(QObject *parent = nullptr); 12 | ~CustomDelegate(); 13 | 14 | void paint(QPainter *painter, const QStyleOptionViewItem &option, 15 | const QModelIndex &index) const; 16 | QSize sizeHint(const QStyleOptionViewItem &option, 17 | const QModelIndex &index) const; 18 | 19 | QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, 20 | const QModelIndex &index) const; 21 | void setModelData(QWidget *editor, QAbstractItemModel *model, 22 | const QModelIndex &index) const; 23 | 24 | private: 25 | QLineEdit *editor; 26 | }; 27 | 28 | #endif // CUSTOM_DELEGATE_H 29 | -------------------------------------------------------------------------------- /src/mvc/cpp/item_delegate/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/item_delegate/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include "custom_delegate.h" 4 | #include 5 | #include 6 | 7 | MainWindow::MainWindow(QWidget *parent) 8 | : QMainWindow(parent), ui(new Ui::MainWindow) { 9 | ui->setupUi(this); 10 | 11 | auto model = new QStringListModel(this); 12 | model->setStringList(QStringList() << "Item 1" 13 | << "73" 14 | << "Item 3" 15 | << "Item 4" 16 | << "Item 5" 17 | << "Item 6" 18 | << "Item 7" 19 | << "Item 8" 20 | << "Item 9"); 21 | ui->listView->setModel(model); 22 | ui->listView->setItemDelegate(new CustomDelegate(this)); 23 | } 24 | 25 | MainWindow::~MainWindow() { delete ui; } 26 | -------------------------------------------------------------------------------- /src/mvc/cpp/item_delegate/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/item_delegate/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/mvc/cpp/reorderable_treeview/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/reorderable_treeview/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/reorderable_treeview/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ReorderableTreeView 38 | QTreeView 39 |
reorderable_tree_view.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/cpp/reorderable_treeview/reordable_tree_view.h: -------------------------------------------------------------------------------- 1 | #include "tree_model.h" 2 | #include 3 | 4 | class ReorderableTreeModel : public TreeModel { 5 | 6 | public: 7 | ReorderableTreeModel(const QStringList &headers, QObject *parent = nullptr); 8 | void appendToDestination(QModelIndex sourceIndex, 9 | QModelIndex destinationIndex); 10 | Qt::ItemFlags flags(const QModelIndex &index) const override; 11 | Qt::DropActions supportedDropActions() const override; 12 | }; 13 | 14 | class ReorderableTreeView : public QTreeView { 15 | Q_OBJECT 16 | 17 | public: 18 | ReorderableTreeView(QWidget *parent = nullptr); 19 | ~ReorderableTreeView(); 20 | void setModel(ReorderableTreeModel *model); 21 | ReorderableTreeModel *model() const; 22 | 23 | private: 24 | void startDrag(Qt::DropActions supportedActions); 25 | void dragEnterEvent(QDragEnterEvent *event); 26 | void dropEvent(QDropEvent *event); 27 | void dragMoveEvent(QDragMoveEvent *event); 28 | void dragLeaveEvent(QDragLeaveEvent *event); 29 | 30 | QModelIndex dragIndex; 31 | QModelIndex dropIndex; 32 | }; 33 | -------------------------------------------------------------------------------- /src/mvc/cpp/string_list_model/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(string_list_model 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | insert_element_dialog.cpp 23 | insert_element_dialog.h 24 | insert_element_dialog.ui 25 | ) 26 | 27 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 28 | qt_add_executable(${PROJECT_NAME} 29 | MANUAL_FINALIZATION 30 | ${PROJECT_SOURCES} 31 | ) 32 | # Define target properties for Android with Qt 6 as: 33 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 34 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 35 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 36 | else() 37 | if(ANDROID) 38 | add_library(${PROJECT_NAME} SHARED 39 | ${PROJECT_SOURCES} 40 | ) 41 | # Define properties for Android with Qt 5 after find_package() calls as: 42 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 43 | else() 44 | add_executable(${PROJECT_NAME} 45 | ${PROJECT_SOURCES} 46 | ) 47 | endif() 48 | endif() 49 | 50 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 51 | 52 | set_target_properties(${PROJECT_NAME} PROPERTIES 53 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 54 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 55 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 56 | ) 57 | 58 | if(QT_VERSION_MAJOR EQUAL 6) 59 | qt_finalize_executable(${PROJECT_NAME}) 60 | endif() 61 | -------------------------------------------------------------------------------- /src/mvc/cpp/string_list_model/insert_element_dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "insert_element_dialog.h" 2 | #include "./ui_insert_element_dialog.h" 3 | #include 4 | 5 | InsertElementDialog::InsertElementDialog(QWidget *parent) 6 | : QDialog(parent), ui(new Ui::InsertElementDialog) { 7 | ui->setupUi(this); 8 | 9 | connect(this, &QDialog::accepted, this, [=]() { 10 | auto data = InsertElementData{ui->spinBox->value(), ui->lineEdit->text()}; 11 | emit elementSelected(data); 12 | close(); 13 | }); 14 | } 15 | 16 | void InsertElementDialog::setMaxIndex(int maxIndex) { 17 | ui->spinBox->setMaximum(maxIndex); 18 | } 19 | 20 | InsertElementDialog::~InsertElementDialog() { delete ui; } 21 | -------------------------------------------------------------------------------- /src/mvc/cpp/string_list_model/insert_element_dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef INSERT_ELEMENT_DIALOG_H 2 | #define INSERT_ELEMENT_DIALOG_H 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | namespace Ui { 9 | class InsertElementDialog; 10 | } 11 | QT_END_NAMESPACE 12 | 13 | struct InsertElementData { 14 | int index; 15 | QString text; 16 | }; 17 | 18 | class InsertElementDialog : public QDialog { 19 | Q_OBJECT 20 | 21 | public: 22 | InsertElementDialog(QWidget *parent = nullptr); 23 | ~InsertElementDialog(); 24 | void setMaxIndex(int maxIndex); 25 | 26 | signals: 27 | void elementSelected(InsertElementData data); 28 | 29 | private: 30 | Ui::InsertElementDialog *ui; 31 | }; 32 | #endif // INSERT_ELEMENT_DIALOG_H 33 | -------------------------------------------------------------------------------- /src/mvc/cpp/string_list_model/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/string_list_model/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include "insert_element_dialog.h" 4 | #include 5 | #include 6 | 7 | MainWindow::MainWindow(QWidget *parent) 8 | : QMainWindow(parent), ui(new Ui::MainWindow) { 9 | ui->setupUi(this); 10 | 11 | auto model = new QStringListModel(this); 12 | model->setStringList(QStringList() << "Item 1" 13 | << "Item 2" 14 | << "Item 3"); 15 | ui->listView->setModel(model); 16 | 17 | ui->listView->setEditTriggers(QAbstractItemView::DoubleClicked | 18 | QAbstractItemView::SelectedClicked); 19 | ui->listView->setSelectionMode(QAbstractItemView::MultiSelection); 20 | ui->listView->setDragEnabled(true); 21 | ui->listView->setAcceptDrops(true); 22 | ui->listView->setDropIndicatorShown(true); 23 | ui->listView->setDragDropMode(QAbstractItemView::InternalMove); 24 | 25 | connect(ui->insertButton, &QPushButton::clicked, this, [=]() { 26 | auto dialog = new InsertElementDialog(this); 27 | dialog->setMaxIndex(model->rowCount()); 28 | connect(dialog, &InsertElementDialog::elementSelected, this, 29 | [=](InsertElementData data) { 30 | model->insertRows(data.index, 1); 31 | model->setData(model->index(data.index), data.text); 32 | }); 33 | dialog->show(); 34 | }); 35 | 36 | connect(ui->removeButton, &QPushButton::clicked, this, [=]() { 37 | auto indexes = ui->listView->selectionModel()->selectedIndexes(); 38 | for (auto index : indexes) { 39 | model->removeRow(index.row()); 40 | } 41 | }); 42 | } 43 | 44 | MainWindow::~MainWindow() { delete ui; } 45 | -------------------------------------------------------------------------------- /src/mvc/cpp/string_list_model/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/tree_model/clickable_tree_view.h: -------------------------------------------------------------------------------- 1 | #include "tree_model.h" 2 | #include 3 | 4 | class ClickableTreeView : public QTreeView { 5 | Q_OBJECT 6 | 7 | public: 8 | ClickableTreeView(QWidget *parent = nullptr); 9 | ~ClickableTreeView(); 10 | void addChild(QModelIndex index); 11 | void removeItem(QModelIndex index); 12 | void editItem(QModelIndex index); 13 | void setModel(TreeModel *model); 14 | TreeModel *model() const; 15 | }; 16 | -------------------------------------------------------------------------------- /src/mvc/cpp/tree_model/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/mvc/cpp/tree_model/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include "tree_model.h" 4 | #include 5 | #include 6 | 7 | MainWindow::MainWindow(QWidget *parent) 8 | : QMainWindow(parent), ui(new Ui::MainWindow) { 9 | ui->setupUi(this); 10 | 11 | auto model = new TreeModel(QStringList() << "Col A" 12 | << "Col B" 13 | << "Col C"); 14 | model->appendRow(QStringList() << "Elements"); 15 | model->appendRow(QStringList() << "Items"); 16 | ui->treeView->setModel(model); 17 | } 18 | 19 | MainWindow::~MainWindow() { delete ui; } 20 | -------------------------------------------------------------------------------- /src/mvc/cpp/tree_model/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/mvc/cpp/tree_model/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ClickableTreeView 38 | QTreeView 39 |
clickable_tree_view.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/crypto_ranking_data.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | 4 | @dataclass 5 | class CryptoRankingData: 6 | name: str 7 | iconPath: str 8 | price: float 9 | changePercent: float 10 | volume: float 11 | marketCap: float 12 | -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/crypto_ranking_delegate.py: -------------------------------------------------------------------------------- 1 | from PyQt6.QtCore import QSize, Qt 2 | from PyQt6.QtGui import QColor, QPen 3 | from PyQt6.QtWidgets import QStyledItemDelegate 4 | 5 | 6 | class CryptoRankingDelegate(QStyledItemDelegate): 7 | def __init__(self, parent=None): 8 | super(CryptoRankingDelegate, self).__init__(parent) 9 | 10 | def paint(self, painter, option, index): 11 | column = index.column() 12 | 13 | if column == 2: 14 | value = index.data() 15 | oldPen = painter.pen() 16 | if value < 0: 17 | painter.setPen(QPen(QColor("#8b0000"))) 18 | else: 19 | painter.setPen(QPen(QColor("#006600"))) 20 | icon = index.data(Qt.ItemDataRole.DecorationRole) 21 | pixmap = icon.pixmap(option.decorationSize) 22 | painter.drawPixmap( 23 | option.rect.x() + 1, 24 | option.rect.y() + option.rect.height() / 2 - pixmap.height() / 2, 25 | pixmap, 26 | ) 27 | painter.drawText(option.rect, Qt.AlignmentFlag.AlignCenter, f"{value:.0f}%") 28 | painter.setPen(oldPen) 29 | elif column == 1 or column == 3 or column == 4: 30 | value = index.data() 31 | rect = option.rect 32 | rect.setX(rect.x() + 3) 33 | painter.drawText(rect, option.displayAlignment, f"${value:.0f}%") 34 | else: 35 | super().paint(painter, option, index) 36 | 37 | def sizeHint(self, option, index): 38 | originalSize = QStyledItemDelegate.sizeHint(self, option, index) 39 | return QSize(originalSize.width(), originalSize.height() * 2) 40 | -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/bitcoin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/bitcoin.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/bitcoin_cash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/bitcoin_cash.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/down.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/ethereum.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/ethereum.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/litecoin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/litecoin.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/ripple.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/ripple.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/crypto_ranking/images/up.png -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/main_window.py: -------------------------------------------------------------------------------- 1 | from crypto_ranking_data import CryptoRankingData 2 | from crypto_ranking_table import CryptoRankingModel 3 | from PyQt6 import QtWidgets, uic 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | model = CryptoRankingModel(self) 11 | data = [] 12 | data.append( 13 | CryptoRankingData( 14 | "Bitcoin", 15 | "images/bitcoin.png", 16 | 8100.0, 17 | 11.56, 18 | 210123282.0, 19 | 361739253420.0, 20 | ) 21 | ) 22 | data.append( 23 | CryptoRankingData( 24 | "Ethereum", 25 | "images/ethereum.png", 26 | 730.0, 27 | -10.79, 28 | 76231423.0, 29 | 119951889218.0, 30 | ) 31 | ) 32 | data.append( 33 | CryptoRankingData( 34 | "Ripple", "images/ripple.png", 1.0, 382.23, 3241541123.0, 14866729546.0 35 | ) 36 | ) 37 | data.append( 38 | CryptoRankingData( 39 | "Litecoin", 40 | "images/litecoin.png", 41 | 100.0, 42 | -0.23, 43 | 54256561134144.0, 44 | 3169548426.0, 45 | ) 46 | ) 47 | data.append( 48 | CryptoRankingData( 49 | "Bitcoin Cash", 50 | "images/bitcoin_cash.png", 51 | 800.0, 52 | -99.9921, 53 | 4532452, 54 | 225250788.0, 55 | ) 56 | ) 57 | model.setData(data) 58 | self.tableView.setModel(model) 59 | self.show() 60 | -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | QAbstractScrollArea::AdjustToContents 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 0 31 | 0 32 | 800 33 | 20 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | CryptoRankingTable 42 | QTableView 43 |
crypto_ranking_table.h
44 |
45 |
46 | 47 | 48 |
49 | -------------------------------------------------------------------------------- /src/mvc/python/crypto_ranking/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/emoji_picker_data.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | 4 | @dataclass 5 | class EmojiData: 6 | name: str 7 | iconPath: str 8 | tags: list 9 | 10 | 11 | @dataclass 12 | class EmojiCategory: 13 | name: str 14 | emojis: list 15 | -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/emoji_picker_delegate.py: -------------------------------------------------------------------------------- 1 | from PyQt6.QtCore import QPointF, QSize, Qt 2 | from PyQt6.QtGui import QColor, QLinearGradient 3 | from PyQt6.QtWidgets import QStyle, QStyledItemDelegate 4 | 5 | 6 | class EmojiPickerDelegate(QStyledItemDelegate): 7 | def __init__(self, parent=None): 8 | super().__init__(parent) 9 | 10 | def paint(self, painter, option, index): 11 | rect = option.rect 12 | # make the rect to be square 13 | rect.setWidth(rect.height()) 14 | icon = index.data(Qt.ItemDataRole.DecorationRole) 15 | if icon: 16 | # check if item is hovered 17 | if option.state & QStyle.StateFlag.State_MouseOver: 18 | painter.save() 19 | gradient = QLinearGradient( 20 | QPointF(rect.topLeft()), QPointF(rect.bottomLeft()) 21 | ) 22 | gradient.setColorAt(0, QColor(0, 0, 255, 50)) 23 | gradient.setColorAt(1, QColor(0, 0, 255, 50)) 24 | painter.fillRect(rect, gradient) 25 | painter.restore() 26 | # draw icon as pixmap at the center of the option rect 27 | pixmap_rect = rect 28 | pixmap_rect.setWidth(rect.width() * 0.8) 29 | pixmap_rect.setHeight(rect.height() * 0.8) 30 | pixmap_rect.moveCenter(rect.center()) 31 | pixmap = icon.pixmap(pixmap_rect.size()) 32 | painter.drawPixmap(pixmap_rect, pixmap) 33 | else: 34 | # remove selection from option 35 | option_copy = option 36 | option_copy.state = QStyle.StateFlag.State_Enabled 37 | super().paint(painter, option_copy, index) 38 | 39 | def sizeHint(self, option, index): 40 | original_size = QStyledItemDelegate.sizeHint(self, option, index) 41 | return QSize(original_size.width(), original_size.height() * 2) 42 | -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/boredom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/boredom.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/crying.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/crying.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/emoji.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/emoji.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/happy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/happy.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/hearts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/hearts.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/in_love.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/in_love.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/laugh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/laugh.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/love.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/love.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/nerd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/nerd.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/party.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/party.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/shame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/shame.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/sleeping.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/sleeping.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/smile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/smile.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/star.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/thinking.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/thinking.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/images/upside_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/emoji_picker/images/upside_down.png -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/main_window.py: -------------------------------------------------------------------------------- 1 | from emoji_picker_data import EmojiCategory, EmojiData 2 | from emoji_picker_tree import EmojiPickerModel 3 | from PyQt6 import QtWidgets, uic 4 | from PyQt6.QtCore import QDir 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | uic.loadUi("main_window.ui", self) 11 | model = EmojiPickerModel(self) 12 | 13 | iconPaths = [] 14 | 15 | # find all paths in images folder 16 | dir = QDir("images") 17 | fileInfoList = dir.entryInfoList(QDir.Filter.Files) 18 | for fileInfo in fileInfoList: 19 | iconPaths.append(fileInfo.absoluteFilePath()) 20 | 21 | emojis = [] 22 | 23 | for iconPath in iconPaths: 24 | emojis.append(EmojiData(iconPath, iconPath, list())) 25 | 26 | category = EmojiCategory("Category A", emojis) 27 | model.setColumnCount(7) 28 | model.appendRow(category) 29 | category.name = "Category B" 30 | model.appendRow(category) 31 | 32 | self.treeView.setModel(model) 33 | 34 | self.show() 35 | -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | EmojiPickerTree 38 | QTreeView 39 |
emoji_picker_tree.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/python/emoji_picker/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/mvc/python/file_directory_treeview/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/file_directory_treeview/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/mvc/python/item_delegate/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/item_delegate/main_window.py: -------------------------------------------------------------------------------- 1 | from custom_delegate import CustomDelegate 2 | from PyQt6 import QtWidgets, uic 3 | from PyQt6.QtCore import QStringListModel 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | 11 | model = QStringListModel(self) 12 | model.setStringList( 13 | [ 14 | "Item 1", 15 | "74", 16 | "Item 3", 17 | "Item 4", 18 | "Item 5", 19 | "Item 6", 20 | "Item 7", 21 | "Item 8", 22 | "Item 9", 23 | ] 24 | ) 25 | self.listView.setModel(model) 26 | self.listView.setItemDelegate(CustomDelegate(self)) 27 | self.show() 28 | -------------------------------------------------------------------------------- /src/mvc/python/item_delegate/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /src/mvc/python/item_delegate/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/mvc/python/matrix_view/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/matrix_view/main_window.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from PyQt6 import QtWidgets, uic 3 | 4 | 5 | class MainWindow(QtWidgets.QMainWindow): 6 | def __init__(self): 7 | super().__init__() 8 | uic.loadUi("main_window.ui", self) 9 | 10 | # 2d matrix of floats 11 | matrix = np.random.rand(10, 10) 12 | self.tableWidget.matrix = matrix 13 | self.tableWidget.horizontal_header = [ 14 | "A", 15 | "B", 16 | "C", 17 | "D", 18 | "E", 19 | "F", 20 | "G", 21 | "H", 22 | "I", 23 | "J", 24 | ] 25 | self.colored_cells.toggled.connect( 26 | lambda flag: setattr(self.tableWidget, "colored_cells", flag) 27 | ) 28 | self.format_input.textChanged.connect( 29 | lambda text: setattr(self.tableWidget, "precision", int(text)) 30 | ) 31 | 32 | self.show() 33 | -------------------------------------------------------------------------------- /src/mvc/python/matrix_view/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/mvc/python/matrix_view/requirements.txt -------------------------------------------------------------------------------- /src/mvc/python/reorderable_treeview/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | window = MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/reorderable_treeview/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | 3 | from reorderable_tree_model import ReorderableTreeModel 4 | from tree_model import TreeModel, TreeItem 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | uic.loadUi("main_window.ui", self) 11 | 12 | model = ReorderableTreeModel() 13 | model.appendRow(TreeItem(["Item 1"])) 14 | model.appendRow(TreeItem(["Item 2"])) 15 | 16 | item = model.itemFromIndex(model.index(0, 0)) 17 | item.append_child(TreeItem(["Item 1.1"])) 18 | item.append_child(TreeItem(["Item 1.2"])) 19 | item.append_child(TreeItem(["Item 1.3"])) 20 | 21 | item = model.itemFromIndex(model.index(1, 0)) 22 | item.append_child(TreeItem(["Item 2.1"])) 23 | item.append_child(TreeItem(["Item 2.2"])) 24 | item.append_child(TreeItem(["Item 2.3"])) 25 | 26 | self.treeView.setModel(model) 27 | 28 | self.show() 29 | -------------------------------------------------------------------------------- /src/mvc/python/reorderable_treeview/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ReorderableTreeView 38 | QTreeView 39 |
reorderable_tree_view.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/python/reorderable_treeview/reorderable_tree_model.py: -------------------------------------------------------------------------------- 1 | from PyQt6.QtCore import Qt 2 | 3 | from tree_model import TreeModel 4 | 5 | 6 | class ReorderableTreeModel(TreeModel): 7 | def __init__(self, parent=None): 8 | super().__init__(parent, read_only=True) 9 | 10 | def move_to_destination(self, source_index, destination_index): 11 | source_item = self.itemFromIndex(source_index) 12 | destination_item = self.itemFromIndex(destination_index) 13 | destination_item.append_child(source_item) 14 | self.dataChanged.emit(source_index, source_index) 15 | self.dataChanged.emit(destination_index, destination_index) 16 | 17 | def flags(self, index): 18 | return ( 19 | super().flags(index) 20 | | Qt.ItemFlag.ItemIsDragEnabled 21 | | Qt.ItemFlag.ItemIsDropEnabled 22 | ) 23 | 24 | def supportedDropActions(self): 25 | return Qt.DropAction.CopyAction | Qt.DropAction.MoveAction 26 | -------------------------------------------------------------------------------- /src/mvc/python/reorderable_treeview/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/mvc/python/string_list_model/insert_element_dialog.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | from PyQt6 import QtCore, uic 4 | from PyQt6.QtWidgets import QDialog 5 | 6 | 7 | @dataclass 8 | class InsertElementData: 9 | index: int 10 | text: str 11 | 12 | 13 | class InsertElementDialog(QDialog): 14 | element_selected = QtCore.pyqtSignal(InsertElementData) 15 | 16 | def __init__(self, parent=None): 17 | super().__init__(parent) 18 | uic.loadUi("insert_element_dialog.ui", self) 19 | self.accepted.connect(self.on_accepted) 20 | 21 | def on_accepted(self): 22 | data = InsertElementData(self.spinBox.value(), self.lineEdit.text()) 23 | self.element_selected.emit(data) 24 | self.close() 25 | 26 | def set_max_index(self, max_index): 27 | self.spinBox.setMaximum(max_index) 28 | -------------------------------------------------------------------------------- /src/mvc/python/string_list_model/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/string_list_model/main_window.py: -------------------------------------------------------------------------------- 1 | from insert_element_dialog import InsertElementDialog 2 | from PyQt6 import QtWidgets, uic 3 | from PyQt6.QtCore import QStringListModel 4 | from PyQt6.QtWidgets import QAbstractItemView 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | uic.loadUi("main_window.ui", self) 11 | 12 | model = QStringListModel(self) 13 | model.setStringList(["Item 1", "Item 2", "Item 3"]) 14 | self.listView.setModel(model) 15 | 16 | self.listView.setEditTriggers( 17 | QAbstractItemView.EditTrigger.DoubleClicked 18 | | QAbstractItemView.EditTrigger.SelectedClicked 19 | ) 20 | 21 | self.listView.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection) 22 | self.listView.setDragEnabled(True) 23 | self.listView.setAcceptDrops(True) 24 | self.listView.setDropIndicatorShown(True) 25 | self.listView.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove) 26 | 27 | self.insertButton.clicked.connect(self.insert_element) 28 | self.removeButton.clicked.connect(self.remove_element) 29 | self.show() 30 | 31 | def insert_element(self): 32 | dialog = InsertElementDialog(self) 33 | dialog.set_max_index(self.listView.model().rowCount()) 34 | dialog.element_selected.connect(self.insert_element_data) 35 | dialog.show() 36 | 37 | def insert_element_data(self, data): 38 | self.listView.model().insertRows(data.index, 1) 39 | self.listView.model().setData( 40 | self.listView.model().index(data.index), data.text 41 | ) 42 | 43 | def remove_element(self): 44 | indexes = self.listView.selectionModel().selectedIndexes() 45 | for index in indexes: 46 | self.listView.model().removeRow(index.row()) 47 | -------------------------------------------------------------------------------- /src/mvc/python/string_list_model/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/mvc/python/tree_model/clickable_tree_view.py: -------------------------------------------------------------------------------- 1 | from PyQt6.QtCore import Qt 2 | from PyQt6.QtWidgets import QAbstractItemView, QMenu, QTreeView 3 | from tree_model import TreeItem 4 | 5 | 6 | class ClickableTreeView(QTreeView): 7 | def __init__(self, parent=None): 8 | super().__init__(parent) 9 | self.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) 10 | self.customContextMenuRequested.connect(self.contextMenuEvent) 11 | self.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers) 12 | 13 | def contextMenuEvent(self, pos): 14 | index = self.indexAt(pos) 15 | if not index.isValid(): 16 | return 17 | menu = QMenu() 18 | menu.addAction("Add Child") 19 | menu.addAction("Remove Item") 20 | menu.addAction("Edit Item") 21 | selectedAction = menu.exec(self.mapToGlobal(pos)) 22 | if not selectedAction: 23 | return 24 | value = menu.actions().index(selectedAction) 25 | if value == 0: 26 | self.addChild(index) 27 | elif value == 1: 28 | self.removeItem(index) 29 | elif value == 2: 30 | self.editItem(index) 31 | else: 32 | pass 33 | 34 | def model(self): 35 | return super().model() 36 | 37 | def setModel(self, model): 38 | super().setModel(model) 39 | 40 | def addChild(self, index): 41 | model = self.model() 42 | model.itemFromIndex(index).append_child( 43 | TreeItem(["New Item"], model.itemFromIndex(index)) 44 | ) 45 | self.expandAll() 46 | 47 | def removeItem(self, index): 48 | model = self.model() 49 | model.removeRow(index.row(), index.parent()) 50 | 51 | def editItem(self, index): 52 | self.edit(index) 53 | -------------------------------------------------------------------------------- /src/mvc/python/tree_model/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | window = MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/mvc/python/tree_model/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | from tree_model import TreeModel, TreeItem 3 | 4 | 5 | class MainWindow(QtWidgets.QMainWindow): 6 | def __init__(self): 7 | super().__init__() 8 | uic.loadUi("main_window.ui", self) 9 | 10 | model = TreeModel() 11 | model.appendRow(TreeItem(["Elements"])) 12 | model.appendRow(TreeItem(["Items"])) 13 | self.treeView.setModel(model) 14 | 15 | self.show() 16 | -------------------------------------------------------------------------------- /src/mvc/python/tree_model/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 0 27 | 0 28 | 800 29 | 20 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | ClickableTreeView 38 | QTreeView 39 |
clickable_tree_view.h
40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/mvc/python/tree_model/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/network/temp: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/other/cpp/build_with_docker/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/other/cpp/system_info/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(system_info 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(system_info 18 | main.cpp 19 | ) 20 | target_link_libraries(system_info Qt${QT_VERSION_MAJOR}::Core) 21 | -------------------------------------------------------------------------------- /src/other/cpp/system_info/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QCoreApplication a(argc, argv); 7 | 8 | #ifdef Q_OS_LINUX 9 | qDebug() << "We are on Linux system!"; 10 | #elif defined(Q_OS_WIN32) 11 | qDebug() << "We are on Windows system!"; 12 | #elif defined(Q_OS_MACX) 13 | qDebug() << "We are on Mac system!"; 14 | #else 15 | qDebug() << "Unsupported OS!"; 16 | #endif 17 | 18 | QSysInfo systemInfo; 19 | 20 | qDebug() << "Cpu: " << systemInfo.buildCpuArchitecture(); 21 | qDebug() << "Build: " << systemInfo.buildAbi(); 22 | qDebug() << "Kernel: " << systemInfo.kernelType(); 23 | qDebug() << "Version: " << systemInfo.kernelVersion(); 24 | qDebug() << "Host name: " << systemInfo.machineHostName(); 25 | qDebug() << "Type: " << systemInfo.productType(); 26 | qDebug() << "Version: " << systemInfo.productVersion(); 27 | qDebug() << "Product name: " << systemInfo.prettyProductName(); 28 | 29 | return a.exec(); 30 | } 31 | -------------------------------------------------------------------------------- /src/other/cpp/webcam/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(webcam 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 Gui Multimedia REQUIRED) 15 | find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Gui Multimedia REQUIRED) 16 | 17 | set(PROJECT_SOURCES 18 | main.cpp 19 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(${PROJECT_NAME} 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET ${PROJECT_NAME} 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(${PROJECT_NAME} 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(${PROJECT_NAME} 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Multimedia) 48 | 49 | set_target_properties(${PROJECT_NAME} 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 | ) 54 | 55 | if(QT_VERSION_MAJOR EQUAL 6) 56 | qt_finalize_executable(${PROJECT_NAME}) 57 | endif() 58 | -------------------------------------------------------------------------------- /src/other/cpp/webcam/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/other/cpp/webcam/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | QT_BEGIN_NAMESPACE 9 | namespace Ui { 10 | class MainWindow; 11 | } 12 | QT_END_NAMESPACE 13 | 14 | class MainWindow : public QMainWindow { 15 | Q_OBJECT 16 | 17 | public: 18 | MainWindow(QMainWindow *parent = nullptr); 19 | ~MainWindow(); 20 | 21 | private slots: 22 | void on_devices_currentIndexChanged(const QString &arg1); 23 | void on_connectButton_released(); 24 | void on_recordButton_released(); 25 | 26 | private: 27 | Ui::MainWindow *ui; 28 | bool connected; 29 | bool recording; 30 | QCamera *camera; 31 | QMediaRecorder *recorder; 32 | void toggleConnected(); 33 | void toggleRecording(); 34 | }; 35 | #endif // MAINWINDOW_H 36 | -------------------------------------------------------------------------------- /src/other/python/build_with_docker/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/other/python/resources_and_pyinstaller/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/plots/altair/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/plots/matplotlib/filter_histogram/filter_histogram.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Form 4 | 5 | 6 | 7 | 0 8 | 0 9 | 400 10 | 300 11 | 12 | 13 | 14 | Form 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Qt::Horizontal 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | DoubleRangeSlider 32 | QSlider 33 |
double_range_slider.h
34 |
35 | 36 | HistogramPlot 37 | QWidget 38 |
histogram_plot.h
39 | 1 40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/plots/matplotlib/filter_histogram/histogram_plot.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | 3 | import numpy as np 4 | from plot_widget import PlotWidget 5 | from plot_widget_interface import Labels 6 | 7 | 8 | class HistogramPlot(PlotWidget): 9 | def histogram( 10 | self, 11 | array: np.ndarray, 12 | n_bins: int, 13 | labels: Labels = None, 14 | disabled_bins: List[int] = list(), 15 | enabled_bins_color="#E69F00", 16 | disabled_bins_color="#000000", 17 | ): 18 | self.clear() 19 | n, bins, patches = self.axes.hist( 20 | array, color=enabled_bins_color, alpha=0.5, bins=n_bins 21 | ) 22 | 23 | for i, patch in enumerate(patches): 24 | if i in disabled_bins: 25 | patch.set_facecolor(disabled_bins_color) 26 | 27 | if labels is not None: 28 | self.labels = labels 29 | 30 | self.draw() 31 | -------------------------------------------------------------------------------- /src/plots/matplotlib/filter_histogram/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/plots/matplotlib/filter_histogram/main_window.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from plot_widget import Font, PlotStyle 3 | from PyQt6 import QtWidgets, uic 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | x_points = np.linspace(0, 10, 100) 11 | y_points = np.sin(x_points) 12 | style = PlotStyle( 13 | color_palette=[ 14 | "#E69F00", 15 | "#56B4E9", 16 | "#009E73", 17 | "#F0E442", 18 | "#0072B2", 19 | "#D55E00", 20 | "#CC79A7", 21 | "#000000", 22 | ], 23 | background_color="gray", 24 | line_style="-", 25 | line_width=1, 26 | marker_style="o", 27 | marker_size=0, 28 | grid=True, 29 | font=Font(family="Arial", size=12, color="black"), 30 | ) 31 | self.histogramFilter.style = style 32 | self.histogramFilter.array = y_points 33 | self.show() 34 | -------------------------------------------------------------------------------- /src/plots/matplotlib/filter_histogram/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Open 26 | 27 | 28 | 29 | 30 | Save 31 | 32 | 33 | 34 | 35 | 36 | FilterHistogram 37 | QWidget 38 |
filter_histogram.h
39 | 1 40 |
41 |
42 | 43 | 44 |
45 | -------------------------------------------------------------------------------- /src/plots/matplotlib/filter_histogram/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/plots/matplotlib/filter_histogram/requirements.txt -------------------------------------------------------------------------------- /src/plots/matplotlib/lasso_scatter_plot/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/plots/matplotlib/lasso_scatter_plot/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/plots/matplotlib/lasso_scatter_plot/requirements.txt -------------------------------------------------------------------------------- /src/plots/matplotlib/plot_widget/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/plots/matplotlib/plot_widget/main_window.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from plot_widget import Font, Labels, Legend, PlotStyle 3 | from PyQt6 import QtWidgets, uic 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | x_points = np.linspace(0, 10, 100) 11 | y_points = np.sin(x_points) 12 | style = PlotStyle( 13 | color_palette=[ 14 | "#E69F00", 15 | "#56B4E9", 16 | "#009E73", 17 | "#F0E442", 18 | "#0072B2", 19 | "#D55E00", 20 | "#CC79A7", 21 | "#000000", 22 | ], 23 | background_color="gray", 24 | line_style="-", 25 | line_width=1, 26 | marker_style="o", 27 | marker_size=0, 28 | grid=True, 29 | font=Font(family="Arial", size=12, color="black"), 30 | ) 31 | self.plot_a.style = style 32 | self.plot_a.plot(x_points, y_points, Labels("x", "y"), "sin(x) continuous") 33 | self.plot_a.legend = Legend(["sin(x)"], "upper right") 34 | 35 | style.marker_size = 3 36 | self.plot_b.style = style 37 | self.plot_b.scatter(x_points, y_points, Labels("x", "y"), "sin(x) discrete") 38 | self.plot_b.legend = Legend(["sin(x)"], "upper right") 39 | 40 | self.plot_c.style = style 41 | self.plot_c.histogram(x_points, Labels("x", "y"), "x points histogram") 42 | self.plot_c.legend = Legend(["x points"], "upper right") 43 | 44 | self.plot_d.style = style 45 | self.plot_d.histogram(y_points, Labels("y", "y"), "y points histogram") 46 | self.plot_d.legend = Legend(["y points"], "upper right") 47 | 48 | self.show() 49 | -------------------------------------------------------------------------------- /src/plots/matplotlib/plot_widget/main_window.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Open 39 | 40 | 41 | 42 | 43 | Save 44 | 45 | 46 | 47 | 48 | 49 | PlotWidget 50 | QWidget 51 |
plot_widget.h
52 | 1 53 |
54 |
55 | 56 | 57 |
58 | -------------------------------------------------------------------------------- /src/plots/matplotlib/plot_widget/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/djeada/Qt-Widgets/8128896c61aafebab523ef88a54927042b019e69/src/plots/matplotlib/plot_widget/requirements.txt -------------------------------------------------------------------------------- /src/plots/plotly/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/themes/bright_vibrant/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/themes/classic_dark_mode/temp.md: -------------------------------------------------------------------------------- 1 | 2 | 1. add window filled with common widgets for presentation purpose 3 | 4 | Examples: 5 | * Blazor: https://community.devexpress.com/blogs/aspnet/archive/2019/04/02/announcing-devexpress-ui-for-blazor-razor-components-preview.aspx 6 | * All components: https://setproduct.com/desktop/components 7 | -------------------------------------------------------------------------------- /src/themes/colorful_flat/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/themes/minimal_muted/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/themes/minimalist_monochrome/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/themes/pastel_color/temp.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_painting/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(qwidget_custom_painting 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | arrow_box.cpp 23 | arrow_box.h 24 | ) 25 | 26 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 27 | qt_add_executable(${PROJECT_NAME} 28 | MANUAL_FINALIZATION 29 | ${PROJECT_SOURCES} 30 | ) 31 | # Define target properties for Android with Qt 6 as: 32 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 33 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 34 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 35 | else() 36 | if(ANDROID) 37 | add_library(${PROJECT_NAME} SHARED 38 | ${PROJECT_SOURCES} 39 | ) 40 | # Define properties for Android with Qt 5 after find_package() calls as: 41 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 42 | else() 43 | add_executable(${PROJECT_NAME} 44 | ${PROJECT_SOURCES} 45 | ) 46 | endif() 47 | endif() 48 | 49 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 50 | 51 | set_target_properties(${PROJECT_NAME} PROPERTIES 52 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 53 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 54 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(${PROJECT_NAME}) 59 | endif() 60 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_painting/arrow_box.cpp: -------------------------------------------------------------------------------- 1 | #include "arrow_box.h" 2 | #include 3 | 4 | ArrowBox::ArrowBox(QWidget *parent) : QWidget(parent) {} 5 | 6 | void ArrowBox::paintEvent(QPaintEvent *e) { 7 | // Draw an arrow pointing downwards 8 | 9 | QPainter painter(this); 10 | painter.setRenderHint(QPainter::Antialiasing); 11 | 12 | // Draw a straight line 13 | painter.setPen(QPen(Qt::black, 0.1 * width())); 14 | painter.drawLine(width() / 2, 0, width() / 2, 0.8 * height()); 15 | 16 | // Draw the arrow head 17 | painter.setPen(QPen(Qt::black, 1)); 18 | painter.setBrush(Qt::black); 19 | painter.drawPolygon(QPolygonF() 20 | << QPointF(width() / 2, height()) 21 | << QPointF(width() / 2 - 0.2 * width(), 0.8 * height()) 22 | << QPointF(width() / 2 + 0.2 * width(), 0.8 * height())); 23 | } 24 | 25 | QSize ArrowBox::sizeHint() const { 26 | if (width() < 20 || height() < 20) 27 | return QSize(20, 20); 28 | 29 | return QSize(width(), height()); 30 | } 31 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_painting/arrow_box.h: -------------------------------------------------------------------------------- 1 | #ifndef ARROWBOX_H 2 | #define ARROWBOX_H 3 | 4 | #include 5 | 6 | class ArrowBox : public QWidget { 7 | Q_OBJECT 8 | public: 9 | explicit ArrowBox(QWidget *parent = nullptr); 10 | 11 | protected: 12 | QSize sizeHint() const override; 13 | void paintEvent(QPaintEvent *e); 14 | }; 15 | 16 | #endif // ARROWBOX_H 17 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_painting/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_painting/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent), ui(new Ui::MainWindow) { 6 | ui->setupUi(this); 7 | } 8 | 9 | MainWindow::~MainWindow() { delete ui; } 10 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_painting/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_tooltip/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(custom_tooltip 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(${PROJECT_NAME} 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET ${PROJECT_NAME} 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(${PROJECT_NAME} 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(${PROJECT_NAME} 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(${PROJECT_NAME} 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 | ) 54 | 55 | if(QT_VERSION_MAJOR EQUAL 6) 56 | qt_finalize_executable(${PROJECT_NAME}) 57 | endif() 58 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_tooltip/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_tooltip/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent), ui(new Ui::MainWindow) { 6 | ui->setupUi(this); 7 | 8 | ui->label_1->setToolTip( 9 | "

Custom tooltip

"); 11 | ui->label_2->setToolTip( 12 | "

Custom tooltip

with bullet list

  1. item " 15 | "1
  2. item 2
  3. item 3

"); 16 | ui->label_3->setToolTip( 17 | "

Custom tooltip

with image

"); 21 | } 22 | 23 | MainWindow::~MainWindow() { delete ui; } 24 | -------------------------------------------------------------------------------- /src/widgets/cpp/custom_tooltip/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/widgets/cpp/message_box/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(message_box 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | ) 23 | 24 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 25 | qt_add_executable(${PROJECT_NAME} 26 | MANUAL_FINALIZATION 27 | ${PROJECT_SOURCES} 28 | ) 29 | # Define target properties for Android with Qt 6 as: 30 | # set_property(TARGET ${PROJECT_NAME} 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(${PROJECT_NAME} 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(${PROJECT_NAME} 42 | ${PROJECT_SOURCES} 43 | ) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 48 | 49 | set_target_properties(${PROJECT_NAME} 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 | ) 54 | 55 | if(QT_VERSION_MAJOR EQUAL 6) 56 | qt_finalize_executable(${PROJECT_NAME}) 57 | endif() 58 | -------------------------------------------------------------------------------- /src/widgets/cpp/message_box/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/widgets/cpp/message_box/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | #include 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent), ui(new Ui::MainWindow) { 6 | ui->setupUi(this); 7 | 8 | // connect push button release with show message box 9 | connect(ui->pushButton, &QPushButton::released, this, [&]() { 10 | auto result = QMessageBox::warning( 11 | this, tr("My Application"), 12 | tr("The most recent modifications are not saved.\n" 13 | "Would you like to save them?"), 14 | QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, 15 | QMessageBox::Save); 16 | 17 | switch (result) { 18 | case QMessageBox::Save: 19 | QMessageBox::information(this, tr("My Application"), tr("Save clicked.")); 20 | break; 21 | case QMessageBox::Discard: 22 | QMessageBox::information(this, tr("My Application"), 23 | tr("Discard clicked.")); 24 | break; 25 | case QMessageBox::Cancel: 26 | QMessageBox::information(this, tr("My Application"), 27 | tr("Cancel clicked.")); 28 | break; 29 | default: 30 | break; 31 | } 32 | }); 33 | } 34 | 35 | MainWindow::~MainWindow() { delete ui; } 36 | -------------------------------------------------------------------------------- /src/widgets/cpp/message_box/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/widgets/cpp/status_bar/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | project(status_bar 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 | main_window.cpp 20 | main_window.h 21 | main_window.ui 22 | status_bar.cpp 23 | status_bar.h 24 | ) 25 | 26 | if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) 27 | qt_add_executable(${PROJECT_NAME} 28 | MANUAL_FINALIZATION 29 | ${PROJECT_SOURCES} 30 | ) 31 | # Define target properties for Android with Qt 6 as: 32 | # set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR 33 | # ${CMAKE_CURRENT_SOURCE_DIR}/android) 34 | # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation 35 | else() 36 | if(ANDROID) 37 | add_library(${PROJECT_NAME} SHARED 38 | ${PROJECT_SOURCES} 39 | ) 40 | # Define properties for Android with Qt 5 after find_package() calls as: 41 | # set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") 42 | else() 43 | add_executable(${PROJECT_NAME} 44 | ${PROJECT_SOURCES} 45 | ) 46 | endif() 47 | endif() 48 | 49 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) 50 | 51 | set_target_properties(${PROJECT_NAME} PROPERTIES 52 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 53 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 54 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 55 | ) 56 | 57 | if(QT_VERSION_MAJOR EQUAL 6) 58 | qt_finalize_executable(${PROJECT_NAME}) 59 | endif() 60 | -------------------------------------------------------------------------------- /src/widgets/cpp/status_bar/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/widgets/cpp/status_bar/main_window.cpp: -------------------------------------------------------------------------------- 1 | #include "main_window.h" 2 | #include "./ui_main_window.h" 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent), ui(new Ui::MainWindow) { 6 | ui->setupUi(this); 7 | 8 | // connect start button released with progressBar 9 | connect(ui->startButton, &QPushButton::released, this, [&]() { 10 | if (ui->startButton->isChecked()) { 11 | ui->progressBar->start(); 12 | } else { 13 | ui->progressBar->stop(); 14 | } 15 | }); 16 | 17 | // connect stop button released with progressBar 18 | connect(ui->stopButton, &QPushButton::released, this, [&]() { 19 | if (ui->stopButton->isChecked()) { 20 | ui->progressBar->stop(); 21 | } else { 22 | ui->progressBar->start(); 23 | } 24 | }); 25 | 26 | // connect reset button released with progressBar 27 | connect(ui->resetButton, &QPushButton::released, this, 28 | [&]() { ui->progressBar->setValue(0); }); 29 | 30 | // when stop button is checked, start button is unchecked 31 | // and vice versa 32 | connect(ui->stopButton, &QPushButton::toggled, this, 33 | [&]() { ui->startButton->setChecked(!ui->stopButton->isChecked()); }); 34 | 35 | connect(ui->startButton, &QPushButton::toggled, this, 36 | [&]() { ui->stopButton->setChecked(!ui->startButton->isChecked()); }); 37 | } 38 | 39 | MainWindow::~MainWindow() { delete ui; } 40 | -------------------------------------------------------------------------------- /src/widgets/cpp/status_bar/main_window.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { 8 | class MainWindow; 9 | } 10 | QT_END_NAMESPACE 11 | 12 | class MainWindow : public QMainWindow { 13 | Q_OBJECT 14 | 15 | public: 16 | MainWindow(QWidget *parent = nullptr); 17 | ~MainWindow(); 18 | 19 | private: 20 | Ui::MainWindow *ui; 21 | }; 22 | #endif // MAINWINDOW_H 23 | -------------------------------------------------------------------------------- /src/widgets/cpp/status_bar/status_bar.cpp: -------------------------------------------------------------------------------- 1 | #include "status_bar.h" 2 | 3 | StatusBar::StatusBar(QWidget *parent) 4 | : QProgressBar(parent), timer(new QTimer(this)), timer_interval(300) { 5 | connect(timer, &QTimer::timeout, this, [&]() { 6 | setValue(value() + 1); 7 | start(); 8 | }); 9 | start(); 10 | } 11 | 12 | StatusBar::~StatusBar() { delete timer; } 13 | 14 | void StatusBar::start() { timer->start(timer_interval); } 15 | 16 | void StatusBar::stop() { timer->stop(); } 17 | -------------------------------------------------------------------------------- /src/widgets/cpp/status_bar/status_bar.h: -------------------------------------------------------------------------------- 1 | 2 | /* status bar is QProgressBar with internal QTimer 3 | every second it will update the progress bar by incrementing it by 1 4 | there are functions that allow you to set the progress bar to a specific value 5 | and to start and stop the timer 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | class StatusBar : public QProgressBar { 12 | Q_OBJECT 13 | 14 | public: 15 | StatusBar(QWidget *parent = nullptr); 16 | ~StatusBar(); 17 | 18 | public slots: 19 | void start(); 20 | void stop(); 21 | 22 | private: 23 | QTimer *timer; 24 | int timer_interval; 25 | }; 26 | -------------------------------------------------------------------------------- /src/widgets/cpp/switch_button/temp.md: -------------------------------------------------------------------------------- 1 | Something like ios toggle switch 2 | -------------------------------------------------------------------------------- /src/widgets/python/custom_painting/arrow_box.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtCore, QtGui, QtWidgets 2 | from PyQt6.QtGui import QColor, QPainter, QPen, QPolygonF 3 | 4 | 5 | class ArrowBox(QtWidgets.QWidget): 6 | def __init__(self, parent=None): 7 | super().__init__(parent) 8 | 9 | def sizeHint(self): 10 | if self.width() < 20 or self.height() < 20: 11 | return QtCore.QSize(20, 20) 12 | return QtCore.QSize(self.width(), self.height()) 13 | 14 | def paintEvent(self, e): 15 | painter = QPainter(self) 16 | painter.setRenderHints( 17 | QtGui.QPainter.RenderHint.Antialiasing 18 | | QtGui.QPainter.RenderHint.TextAntialiasing 19 | ) 20 | 21 | pen = QPen(QColor("black")) 22 | pen.setWidth(0.1 * self.width()) 23 | painter.setPen(pen) 24 | painter.drawLine(self.width() / 2, 0, self.width() / 2, 0.8 * self.height()) 25 | pen.setWidth(1) 26 | painter.setBrush(QColor("black")) 27 | painter.drawPolygon( 28 | QPolygonF() 29 | << QtCore.QPointF(self.width() / 2, self.height()) 30 | << QtCore.QPointF( 31 | self.width() / 2 - 0.2 * self.width(), 0.8 * self.height() 32 | ) 33 | << QtCore.QPointF( 34 | self.width() / 2 + 0.2 * self.width(), 0.8 * self.height() 35 | ) 36 | ) 37 | -------------------------------------------------------------------------------- /src/widgets/python/custom_painting/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from PyQt6 import QtWidgets, uic 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | self.show() 11 | 12 | 13 | def main(): 14 | app = QtWidgets.QApplication(sys.argv) 15 | MainWindow() 16 | app.exec() 17 | 18 | 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /src/widgets/python/custom_painting/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/widgets/python/custom_tooltip/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from PyQt6 import QtWidgets, uic 4 | 5 | 6 | class MainWindow(QtWidgets.QMainWindow): 7 | def __init__(self): 8 | super().__init__() 9 | uic.loadUi("main_window.ui", self) 10 | 11 | self.label_1.setToolTip( 12 | '

Custom tooltip

' 14 | ) 15 | self.label_2.setToolTip( 16 | '

Custom tooltip

with bullet list

  1. item ' 19 | "1
  2. item 2
  3. item 3

" 20 | ) 21 | self.label_3.setToolTip( 22 | '

Custom tooltip

with image

' 26 | ) 27 | 28 | self.show() 29 | 30 | 31 | def main(): 32 | app = QtWidgets.QApplication(sys.argv) 33 | MainWindow() 34 | app.exec() 35 | 36 | 37 | if __name__ == "__main__": 38 | main() 39 | -------------------------------------------------------------------------------- /src/widgets/python/custom_tooltip/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/widgets/python/double_range_slider/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/widgets/python/double_range_slider/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | 3 | 4 | class MainWindow(QtWidgets.QMainWindow): 5 | def __init__(self): 6 | super().__init__() 7 | uic.loadUi("main_window.ui", self) 8 | self.show() 9 | -------------------------------------------------------------------------------- /src/widgets/python/double_range_slider/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/widgets/python/message_box/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from PyQt6 import QtWidgets, uic 4 | from PyQt6.QtWidgets import QMessageBox 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | uic.loadUi("main_window.ui", self) 11 | self.pushButton.released.connect(self.show_message_box) 12 | self.show() 13 | 14 | def show_message_box(self): 15 | message_box = QMessageBox() 16 | message_box.setIcon(QMessageBox.Icon.Warning) 17 | message_box.setWindowTitle("My Application") 18 | message_box.setText( 19 | "The most recent modifications are not saved.\nWould you like to save them?" 20 | ) 21 | message_box.setStandardButtons( 22 | QMessageBox.StandardButton.Save 23 | | QMessageBox.StandardButton.Discard 24 | | QMessageBox.StandardButton.Cancel 25 | ) 26 | message_box.setDefaultButton(QtWidgets.QMessageBox.StandardButton.Save) 27 | result = message_box.exec() 28 | 29 | if result == QtWidgets.QMessageBox.StandardButton.Save: 30 | QtWidgets.QMessageBox.information( 31 | None, "My Application", "Save clicked." 32 | ).show() 33 | elif result == QtWidgets.QMessageBox.StandardButton.Discard: 34 | QtWidgets.QMessageBox.information( 35 | None, "My Application", "Discard clicked." 36 | ).show() 37 | elif result == QtWidgets.QMessageBox.StandardButton.Cancel: 38 | QtWidgets.QMessageBox.information( 39 | None, "My Application", "Cancel clicked." 40 | ).show() 41 | else: 42 | pass 43 | 44 | 45 | def main(): 46 | app = QtWidgets.QApplication(sys.argv) 47 | MainWindow() 48 | app.exec() 49 | 50 | 51 | if __name__ == "__main__": 52 | main() 53 | -------------------------------------------------------------------------------- /src/widgets/python/message_box/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/widgets/python/status_bar/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from PyQt6 import QtWidgets, uic 4 | from PyQt6.QtCore import pyqtSlot 5 | 6 | 7 | class MainWindow(QtWidgets.QMainWindow): 8 | def __init__(self): 9 | super().__init__() 10 | uic.loadUi("main_window.ui", self) 11 | 12 | # connect reset button released with progressBar 13 | self.resetButton.clicked.connect(self.slot_resetButton) 14 | 15 | # when stop button is checked, start button is unchecked 16 | # and vice versa 17 | self.stopButton.toggled.connect(lambda flag: self.slot_stopButton(flag)) 18 | 19 | self.startButton.toggled.connect(lambda flag: self.slot_startButton(flag)) 20 | 21 | self.show() 22 | 23 | @pyqtSlot() 24 | def slot_resetButton(self): 25 | print("rest") 26 | self.progressBar.setValue(0) 27 | 28 | @pyqtSlot() 29 | def slot_stopButton(self, flag): 30 | self.startButton.setChecked(not flag) 31 | if flag: 32 | self.progressBar.stop() 33 | 34 | @pyqtSlot() 35 | def slot_startButton(self, flag): 36 | self.stopButton.setChecked(not flag) 37 | if flag: 38 | self.progressBar.start() 39 | 40 | 41 | def main(): 42 | app = QtWidgets.QApplication(sys.argv) 43 | MainWindow() 44 | app.exec() 45 | 46 | 47 | if __name__ == "__main__": 48 | main() 49 | -------------------------------------------------------------------------------- /src/widgets/python/status_bar/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/widgets/python/status_bar/status_bar.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtCore, QtWidgets 2 | 3 | 4 | class StatusBar(QtWidgets.QProgressBar): 5 | def __init__(self, parent=None): 6 | super().__init__(parent) 7 | self.timer = QtCore.QTimer(self) 8 | self.timer_interval = 300 9 | self.timer.timeout.connect(self.slot_timer) 10 | self.start() 11 | 12 | def start(self): 13 | self.timer.start(self.timer_interval) 14 | 15 | def stop(self): 16 | self.timer.stop() 17 | 18 | def slot_timer(self): 19 | self.setValue(self.value() + 1) 20 | -------------------------------------------------------------------------------- /src/widgets/python/switch_button/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/widgets/python/switch_button/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | 3 | 4 | class MainWindow(QtWidgets.QMainWindow): 5 | def __init__(self): 6 | super().__init__() 7 | uic.loadUi("main_window.ui", self) 8 | 9 | self.show() 10 | -------------------------------------------------------------------------------- /src/widgets/python/switch_button/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 -------------------------------------------------------------------------------- /src/widgets/python/toggle_button/main.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from main_window import MainWindow 4 | from PyQt6 import QtWidgets 5 | 6 | 7 | def main(): 8 | app = QtWidgets.QApplication(sys.argv) 9 | MainWindow() 10 | app.exec() 11 | 12 | 13 | if __name__ == "__main__": 14 | main() 15 | -------------------------------------------------------------------------------- /src/widgets/python/toggle_button/main_window.py: -------------------------------------------------------------------------------- 1 | from PyQt6 import QtWidgets, uic 2 | 3 | 4 | class MainWindow(QtWidgets.QMainWindow): 5 | def __init__(self): 6 | super().__init__() 7 | uic.loadUi("main_window.ui", self) 8 | self.toggleButtonA.addItems(["A", "B", "C"]) 9 | self.toggleButtonB.addItem("Single") 10 | self.toggleButtonC.addItems(["Tree View", "Map View"]) 11 | 12 | self.show() 13 | -------------------------------------------------------------------------------- /src/widgets/python/toggle_button/requirements.txt: -------------------------------------------------------------------------------- 1 | PyQt6 --------------------------------------------------------------------------------