Дмитрий
Aug. 12, 2017, 12:58 a.m.

Using the capabilities of winExtras when working with QML

Content

Some time ago I wrote several articles about using the QtWinExtras library, which opens access to special features that are available only for Windows. Now I want to say a few words about how to repeat, too, using QML. For this we need to create a Qt Quick project, connect the winextras module in the project

  1. import QtWinExtras 1.0

And use 3 objects: TaskbarButton to create a progress bar and manage it, ThumbnailToolBar for work with buttons on the pop-up window of the taskbar and JumpList (for working with jumpList). Also add FileDialog for the full work of jumpList.


For TaskbarButton, you need to set the id properties (to access this object from outside), progress.visible: true. Additionally, you can set the overlay.iconSource icon.

In ThumbnailToolBar we create the ThumbnailToolButton (from one to seven) buttons, set the icons and write the click processing.

In JumpList, the recent section is visible to show the last opened files and frequent to display frequently opened files.

  1. JumpList {
  2. id: jumpList
  3. recent.visible: true
  4. frequent.visible: true
  5. }

Do not forget that the file extensions that fall into the jumpList must be registered in the registry. Therefore, add the function associateFileTypes () to the main file, as shown in the previous article. .

Another curious possibility is the setting of the transparency of the window. To do this, you need the DwmFeatures object. Its blurBehindEnabled property makes the window transparent if its value is true. If you set it to false, the background color becomes black. I also note that the transparency can be set using the opacity property of the Window object. It differs from blurBehindEnabled in that the latter can have only 2 states (transparent and opaque) and makes only the main part of the window transparent (without widgets placed on it), while opacity sets the degree of transparency and makes the whole window transparent with all the widgets And a frame. Another 4 leftGlassMargin, rightGlassMargin, topGlassMargin, and bottomGlassMargin properties are responsible for the size of the extra margin from the left, right, top, and bottom side of the window, respectively. Indentation values ​​are specified in pixels. The default values ​​are 0. I do not see the application application in these properties, but I wrote about them for completeness.

Main.qml

  1. import QtQuick 2.6
  2. import QtQuick.Window 2.2
  3. import QtQuick.Controls 2.0
  4. import QtQuick.Dialogs 1.0
  5. import QtWinExtras 1.0
  6.  
  7. Window {
  8. visible: true
  9. width: 640
  10. height: 480
  11. title: qsTr("Hello WinExtras")
  12. DwmFeatures {
  13. id: dwmFeatures
  14. blurBehindEnabled: true
  15. leftGlassMargin : 10
  16. rightGlassMargin : 10
  17. topGlassMargin : 10
  18. bottomGlassMargin : 10
  19. excludedFromPeek : false
  20. peekDisallowed : false
  21. flip3DPolicy: QtWin.FlipExcludeBelow
  22. }
  23.  
  24. Button{
  25. x:100
  26. y:200
  27. width:200
  28. height: 100
  29. text: "button"
  30. }
  31.  
  32. TaskbarButton {
  33. id: taskbarButton
  34. //overlay.iconSource: "loading.png"
  35. overlay.accessibleDescription: "Loading"
  36. progress.visible: true
  37. progress.value: 50
  38. }
  39.  
  40. ThumbnailToolBar {
  41. ThumbnailToolButton { iconSource: "r.png"; tooltip: "Next"; onClicked: taskbarButton.progress.value = taskbarButton.progress.value+1 }
  42. ThumbnailToolButton { iconSource: "l.png"; tooltip: "Prep"; onClicked: taskbarButton.progress.value = taskbarButton.progress.value-1 }
  43. ThumbnailToolButton { iconSource: "pause.png"; tooltip: "Pause"; onClicked: taskbarButton.progress.setPaused(!taskbarButton.progress.paused) }
  44. ThumbnailToolButton { interactive: false; flat: true }
  45. ThumbnailToolButton { iconSource: "open.png"; tooltip: "OpenFile"; onClicked: fileDialog.open()}
  46. ThumbnailToolButton { iconSource: "exit.png"; tooltip: "Open"; onClicked: Qt.quit() }
  47. }
  48.  
  49. JumpList {
  50. id: jumpList
  51. recent.visible: true
  52. frequent.visible: true
  53. //tasks.visible: true
  54. }
  55.  
  56. FileDialog {
  57. id: fileDialog
  58. selectFolder: true
  59. title: "Please choose a file"
  60. folder: shortcuts.home
  61. onAccepted: {
  62. console.log("You chose: " + fileDialog.fileUrls)
  63. }
  64. }
  65. }

Main.cpp

  1. clude <QFileInfo>
  2. #include <QGuiApplication>
  3. #include <QQmlApplicationEngine>
  4. #include <QDir>
  5. #include <QSettings>
  6.  
  7. static void associateFileTypes(const QStringList &fileTypes)
  8. {
  9. QString displayName = QGuiApplication::applicationDisplayName();
  10. QString filePath = QCoreApplication::applicationFilePath();
  11. QString fileName = QFileInfo(filePath).fileName();
  12. //qDebug() << displayName << filePath << fileName;
  13. QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\Applications\\" + fileName, QSettings::NativeFormat);
  14. settings.setValue("FriendlyAppName", displayName);
  15. settings.beginGroup("SupportedTypes");
  16. foreach (const QString& fileType, fileTypes)
  17. settings.setValue(fileType, QString());
  18. settings.endGroup();
  19. settings.beginGroup("shell");
  20. settings.beginGroup("open");
  21. settings.setValue("FriendlyAppName", displayName);
  22. settings.beginGroup("Command");
  23. settings.setValue(".", QChar('"') + QDir::toNativeSeparators(filePath) + QString("\" \"%1\""));
  24. }
  25.  
  26. int main(int argc, char *argv[])
  27. {
  28. QGuiApplication app(argc, argv);
  29. app.setApplicationDisplayName("QtWinExtras Test");
  30. associateFileTypes(QStringList(".txt"));
  31. QQmlApplicationEngine engine;
  32. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  33. return app.exec();
  34. }

Text of the program

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html