{"id":16672795,"url":"https://github.com/brcontainer/qt-helper","last_synced_at":"2025-04-09T20:02:41.893Z","repository":{"id":18547092,"uuid":"21748319","full_name":"brcontainer/qt-helper","owner":"brcontainer","description":"A repository of libs for applications in Qt","archived":false,"fork":false,"pushed_at":"2024-04-15T11:34:32.000Z","size":286,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T20:02:25.657Z","etag":null,"topics":["c-plus-plus","qt","qt4","qt5","qt6"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brcontainer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-07-11T19:18:20.000Z","updated_at":"2024-04-14T08:56:45.000Z","dependencies_parsed_at":"2024-04-15T12:51:49.980Z","dependency_job_id":"3c4e9e4f-ab67-4c7d-8007-4210bfe44898","html_url":"https://github.com/brcontainer/qt-helper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brcontainer%2Fqt-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brcontainer%2Fqt-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brcontainer%2Fqt-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brcontainer%2Fqt-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brcontainer","download_url":"https://codeload.github.com/brcontainer/qt-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103865,"owners_count":21048245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","qt","qt4","qt5","qt6"],"created_at":"2024-10-12T12:07:20.735Z","updated_at":"2025-04-09T20:02:41.827Z","avatar_url":"https://github.com/brcontainer.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QtHelper\n\nSimple Qt library to improve and help in their projects\n\n![Usage sample](sample.png)\n\n## Usage:\n\nFor use all classes add in your project something like this:\n\n```\nQT += core gui webkitwidgets network\n\ngreaterThan(QT_MAJOR_VERSION, 4): QT += widgets\n\nTARGET = application\nTEMPLATE = app\n\nSOURCES  += main.cpp\n\ninclude($$PWD/vendor/qt-helper/qt-helper.pri)\n```\n\n**Note:** `vendor` is just a suggestion on how to organize your folders, to add third-party libraries:\n\n```\nsample/\n├─── main.cpp\n├─── mainwindow.cpp\n├─── mainwindow.h\n├─── mainwindow.ui\n├─── sample.pro\n└─── vendor/\n     └─── qt-helper/\n          ├─── application/\n          │    ├─── oneinstanceapp.cpp\n          │    ├─── oneinstanceapp.h\n          │    ├─── oneinstanceapp.pri\n          │    ├─── proxystyle.cpp\n          │    ├─── proxystyle.h\n          │    └─── proxystyle.pri\n          │\n          ├─── desktop/\n          │    ├─── openexternal.cpp\n          │    ├─── openexternal.h\n          │    ├─── openexternal.pri\n          │    ├─── shortcut.cpp\n          │    ├─── shortcut.h\n          │    ├─── shortcut.pri\n          │    ├─── trackmouse.cpp\n          │    ├─── trackmouse.h\n          │    └─── trackmouse.pri\n          │\n          ├─── network/\n          │    ├─── networkmanager.cpp\n          │    ├─── networkmanager.h\n          │    └─── networkmanager.pri\n          │\n          └─── webkit/\n               ├─── webglobals.cpp\n               ├─── webglobals.h\n               └─── webglobals.pri\n```\n\n## Application\n\nThe classes in this scope are used to adjust or control anything related to your application, or `QApplication`, or add extra functionality.\n\n### oneinstanceapp\n\nThis class allows your application to only have one instance. Usage example:\n\n```cpp\n#include \"mainwindow.h\"\n#include \"oneinstanceapp.h\"\n\nint main(int argc, char *argv[])\n{\n    OneInstanceApp app(\"instance\", argc, argv);\n\n    MainWindow win;\n    win.show();\n\n    return app.exec();\n}\n```\n\n\u003e For include ony `OnceInstanceApp` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/application/oneinstanceapp.pri)\n\u003e ```\n\n### proxystyle\n\nAdjust the style and improve the combobox popup:\n\n```cpp\n#include \"mainwindow.h\"\n#include \"proxystyle.h\"\n#include \u003cQApplication\u003e\n\nint main(int argc, char *argv[])\n{\n    QApplication app(argc, argv);\n\n    app.setStyle(new ProxyStyle());\n\n    MainWindow win;\n    win.show();\n\n    return app.exec(\"~instance\");\n}\n```\n\nMethod | Description\n--- | ---\n`new ProxyStyle()` | Default theme\n`new ProxyStyle(\"Fusion\")` | Define Fusion theme in application\n`new ProxyStyle(\"Windows\")` | Define Windows theme in application\n`new ProxyStyle(\"WindowsXP\")` | Define Windows XP theme in application\n`new ProxyStyle(\"WindowsVista\")` | Define Windows Vista theme in application\n`new ProxyStyle(\"Motif\")` | Define Motif theme in application\n`new ProxyStyle(\"CDE\")` | Define CDE theme in application\n`new ProxyStyle(\"Plastique\")` | Define Plastique theme in application\n`new ProxyStyle(\"Cleanlooks\")` | Define Cleanlooks theme in application\n\n\u003e **Note:** Default themes depend on system availability or Qt version\n\nFor custom theme you can extends like this:\n\n```cpp\nclass CustomStyle : public ProxyStyle\n{\n    Q_OBJECT\n\npublic:\n    CustomStyle();\n    ...\n}\n\n...\n\napp.setStyle(new CustomStyle());\n\n...\n```\n\nMore details:\n\n- Qt5: https://doc.qt.io/qt-5/qtwidgets-widgets-styles-example.html\n- Qt6: https://doc.qt.io/qt-6.2/qtwidgets-widgets-styles-example.html\n- Gallery: https://doc.qt.io/qt-6/gallery.html\n\n\u003e For include ony `ProxyStyle` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/aplication/proxystyle.pri)\n\u003e ```\n\n## Desktop\n\n### openexternal\n\nPrevent freeze (or crash) apps with `QDesktopServices::openUrl`:\n\n```cpp\nMainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)\n{\n    ui-\u003esetupUi(this);\n\n    QObject::connect(ui-\u003ebtn1, SIGNAL(clicked()), this, SLOT(showFileInExplorer()));\n    QObject::connect(ui-\u003ebtn2, SIGNAL(clicked()), this, SLOT(openFile()));\n}\n\nvoid MainWindow::showFileInExplorer()\n{\n    OpenExternal::showInFolder(\"C:/foder/file.txt\");\n}\n\nvoid MainWindow::openFile()\n{\n    OpenExternal::open(\"C:/foder/file.txt\");\n}\n```\n\nMethod | Description\n--- | ---\n`OpenExternal::open(\"C:/foo/bar/\")` | Open default file manager (`explorer.exe` in Windows or `Finder` in macOS)\n`OpenExternal::open(\"C:/foo/file.txt\")` | Try open with default program, if failed try use `OpenExternal::showInFolder`\n`OpenExternal::showInFolder(\"C:/foo/file.txt\")` | In Windows is equivalent to `explorer /select,C:\\foder\\file.txt` command\n`OpenExternal::showInFolder(\"/Users/sample/Desktop/foo.txt\")` | In macOS is equivalent to `open -R /Users/sample/Desktop/foo.txt` command\n\n\u003e For include ony `OpenExternal` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/desktop/openexternal.pri)\n\u003e ```\n\n### shortcut\n\nThese methods make it easier to add shortcuts to widgets. Using:\n\n```cpp\nShortcut::keys(widget, \"Alt+F5\", this, SLOT(...));\n```\n\nIs equivalent to:\n\n```cpp\nQAction *action = new QAction(widget);\nQObject::connect(action, SIGNAL(triggered()), this, SLOT(...));\nwidget-\u003eaddAction(action);\nwidget-\u003esetShortcuts(QKeySequence(\"Alt+F5\"));\n```\n\nExample:\n\n```cpp\n#include \"shortcut.h\"\n\nMainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)\n{\n    ui-\u003esetupUi(this);\n\n    Shortcut::keys(this, \"Ctrl+w\", this, SLOT(close()));\n    Shortcut::keys(this, \"F12\", this, SLOT(screenshot()));\n}\n\nvoid MainWindow::screenshot()\n{\n    ...\n}\n```\n\nMethod | Description\n--- | ---\n`Shortcut::bind(QWidget*, QObject*, char*)` | This makes it easier to create a shortcut with a slot and add it to a Widget\n`Shortcut::keys(QWidget*, QKeySequence \u0026shortcut, QObject*, char*)` | Define shortcut to widget with `QKeySequence`\n`Shortcut::keys(QWidget*, QString, QObject*, char*, bool)` | Is equivalent to `Shortcut::keys(QWidget*, QKeySequence(QString*), ...)`\n`Shortcut::keys(QWidget*, QList\u003cQKeySequence\u003e \u0026shortcuts, QObject*, char*)` | Define a shortcut of `QList\u003cQKeySequence\u003e`\n`Shortcut::keys(QWidget*, QKeySequence::StandardKey, QObject*, char*)` | Define a shortcut with a standard key. More details in: https://doc.qt.io/qt-6/qkeysequence.html#standard-shortcuts\n\n\u003e For include ony `OnceInstanceApp` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/desktop/shortcut.pri)\n\u003e ```\n\n### trackmouse\n\n```cpp\n#include \"trackmouse.h\";\n\n...\n\nSample::Sample(QWidget *parent) : QWidget(parent)\n{\n    TrackMouse *track = new TrackMouse(this);\n    QObject::connect(track, SIGNAL(position(QPoint)), this, SLOT(capture(QPoint)));\n    track-\u003esetDelay(1000); // Set delay (default is 100 ms)\n    track-\u003esetWidget(this, true);\n    track-\u003eenable(true);\n}\n\nSample::capture(const QPoint position)\n{\n    qDebug() \u003c\u003c position;\n}\n```\n\n\u003e For include ony `TrackMouse` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/desktop/trackmouse.pri)\n\u003e ```\n\n## Network\n\n### networkmanager\n\nThis class fix problems with \"Response unknown\" that occurs with some servers:\n\n```cpp\n#include \"networkmanager.h\"\n\n...\nNetworkManager *manager = new NetworkManager;\nmanager-\u003ecookieJar(cookiejar); // Get default jar\n\n// Set NetworkManager to QWebPage\nui-\u003ewebView-\u003epage()-\u003esetNetworkAccessManager(manager);\n```\n\nIn requests for unknown schemes, you can implement a customized response or perform various actions, such as opening external programs:\n\n```cpp\nNetworkManager *manager = new NetworkManager;\n\nQObject::connect(manager, SIGNAL(unknownScheme(QString,QNetworkReply*)), this, SLOT(myImplemetation(QString,QNetworkReply*)));\n\nvoid MainWindow::myImplemetation(const QString \u0026scheme, QNetworkReply *reply)\n{\n    if (scheme == \"tel\") {\n        // Open phone application (can try uses `QDesktopServices::openUrl(reply.url())`)\n    } else if (scheme == \"custom\") {\n        // custom reply\n    }\n}\n```\n\n\u003e For include ony `NetworkManager` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/network/networkmanager.pri)\n\u003e ```\n\n## Webkit\n\n### webglobals\n\nAdjustments for QtWebkit made easy:\n\n```cpp\nWebGlobals configs();\nconfigs.developer(true); // Enable developer tools\n```\n\nMethod | Description\n--- | ---\n`void WebGlobals::developer(const bool enable)` | Enable or disable developer tools\n`QWebSettings *WebGlobals::configs()` | Same as `QWebSettings::globalSettings()`\n`void WebGlobals::setStyle(const QString path)` | Specifies the location of a user stylesheet to load with every web page\n`void WebGlobals::setFont(const int size, const QString font)` | Sets the font size and sets the actual font family to family for the specified generic family, which\n`QIcon WebGlobals::getIcon(const QString url)` | Get icon from URL\n`QString WebGlobals::getPath(const WebData type)` | Get full path from your browser profile data\n`QString WebGlobals::getPath(WebData::All)` | Get path your browser profile\n`QString WebGlobals::getPath(WebData::AppCache)` | Get cache path from  your browser profile\n`QString WebGlobals::getPath(WebData::LocalStorage)` | Get localstorage path from  from your browser profile\n`QString WebGlobals::getPath(WebData::OfflineStorage)` | Get offline path from  from your browser profile\n`QString WebGlobals::getPath(WebData::Icons)` | Get icons path from  from your browser profile\n`QString WebGlobals::getPath(WebData::Temporary)` | Get temporary path from  your browser profile\n`bool WebGlobals::erase(const WebData type)` | Erase data by type from your browser profile data\n`bool WebGlobals::erase(WebData::All)` | Erase all data from your browser profile data\n`bool WebGlobals::erase(WebData::AppCache)` | Erase cache from your browser profile data\n`bool WebGlobals::erase(WebData::LocalStorage)` | Erase localstorage data from your browser profile data\n`bool WebGlobals::erase(WebData::OfflineStorage)` | Erase offline data from your browser profile data\n`bool WebGlobals::erase(WebData::Icons)` | Erase icons data from your browser profile data\n`bool WebGlobals::erase(WebData::Temporary)` | Erase temporary data your browser profile data\n\n\u003e For include ony `WebGlobals` in your application put in your `.pro`, eg.:\n\u003e\n\u003e ```\n\u003e ...\n\u003e\n\u003e SOURCES  += main.cpp\n\u003e\n\u003e include($$PWD/vendor/qt-helper/web/webglobals.pri)\n\u003e ```\n\n## Sample/Example\n\nThe sample APIs are located at [./sample](./sample), you can open the \"sample.pro\" file in QtDesigner, or compile via the command line.\n\nDeploy in debug mode with command line:\n\n```\ncd /home/foo/bar/qt-helpder/sample\nqmake \"CONFIG += console warn_on debug\" sample.pro\nmake\n./debug/sample\n```\n\nFor release:\n\n```\ncd /home/foo/bar/qt-helpder/sample\nqmake \"CONFIG += release\" sample.pro\nmake\n./release/sample\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrcontainer%2Fqt-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrcontainer%2Fqt-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrcontainer%2Fqt-helper/lists"}