Дмитрий
ДмитрийAug. 11, 2017, 2:58 p.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

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.

JumpList {
    id: jumpList
    recent.visible: true
    frequent.visible: true
}

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

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.0
import QtQuick.Dialogs 1.0
import QtWinExtras 1.0

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello WinExtras")
    DwmFeatures {
        id: dwmFeatures
        blurBehindEnabled: true
        leftGlassMargin : 10
        rightGlassMargin : 10
        topGlassMargin : 10
        bottomGlassMargin : 10
        excludedFromPeek : false
        peekDisallowed : false
        flip3DPolicy: QtWin.FlipExcludeBelow
    }

    Button{
        x:100
        y:200
        width:200
        height: 100
        text: "button"
    }

    TaskbarButton {
        id: taskbarButton 
       //overlay.iconSource: "loading.png" 
       overlay.accessibleDescription: "Loading"
        progress.visible: true
        progress.value: 50
    } 

   ThumbnailToolBar {
        ThumbnailToolButton { iconSource: "r.png"; tooltip: "Next"; onClicked: taskbarButton.progress.value = taskbarButton.progress.value+1 } 
       ThumbnailToolButton { iconSource: "l.png"; tooltip: "Prep"; onClicked: taskbarButton.progress.value = taskbarButton.progress.value-1 }
        ThumbnailToolButton { iconSource: "pause.png"; tooltip: "Pause"; onClicked: taskbarButton.progress.setPaused(!taskbarButton.progress.paused) }
        ThumbnailToolButton { interactive: false; flat: true }
        ThumbnailToolButton { iconSource: "open.png"; tooltip: "OpenFile"; onClicked: fileDialog.open()}
        ThumbnailToolButton { iconSource: "exit.png"; tooltip: "Open"; onClicked: Qt.quit() }
    }

    JumpList {
        id: jumpList 
       recent.visible: true 
       frequent.visible: true
        //tasks.visible: true 
    }

    FileDialog {
          id: fileDialog
          selectFolder: true
          title: "Please choose a file"
          folder: shortcuts.home
          onAccepted: {
              console.log("You chose: " + fileDialog.fileUrls)
          }
      }
}

Main.cpp

clude <QFileInfo>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDir>
#include <QSettings>

static void associateFileTypes(const QStringList &fileTypes)
{
    QString displayName = QGuiApplication::applicationDisplayName();
    QString filePath = QCoreApplication::applicationFilePath();
    QString fileName = QFileInfo(filePath).fileName();
    //qDebug() << displayName << filePath << fileName;
    QSettings settings("HKEY_CURRENT_USER\\Software\\Classes\\Applications\\" + fileName, QSettings::NativeFormat);
    settings.setValue("FriendlyAppName", displayName);
    settings.beginGroup("SupportedTypes");
    foreach (const QString& fileType, fileTypes)
        settings.setValue(fileType, QString());
    settings.endGroup();
    settings.beginGroup("shell");
    settings.beginGroup("open");
    settings.setValue("FriendlyAppName", displayName);
    settings.beginGroup("Command");
    settings.setValue(".", QChar('"') + QDir::toNativeSeparators(filePath) + QString("\" \"%1\""));
}

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    app.setApplicationDisplayName("QtWinExtras Test");
    associateFileTypes(QStringList(".txt"));
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}

Text of the program

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

Comments

Only authorized users can post comments.
Please, Log in or Sign up
SH

C++ - Test 001. The first program and data types

  • Result:33points,
  • Rating points-10
г
  • ги
  • April 23, 2024, 10:51 p.m.

C++ - Test 005. Structures and Classes

  • Result:41points,
  • Rating points-8
l
  • laei
  • April 23, 2024, 4:19 p.m.

C ++ - Test 004. Pointers, Arrays and Loops

  • Result:10points,
  • Rating points-10
Last comments
k
kmssrFeb. 9, 2024, 2:43 a.m.
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVADec. 25, 2023, 6:30 p.m.
Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
J
JonnyJoDec. 25, 2023, 4:38 p.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
G
GvozdikDec. 19, 2023, 5:01 a.m.
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
G
GarApril 22, 2024, 12:46 p.m.
Clipboard Как скопировать окно целиком в clipb?
DA
Dr Gangil AcademicsApril 20, 2024, 2:45 p.m.
Unlock Your Aesthetic Potential: Explore MSC in Facial Aesthetics and Cosmetology in India Embark on a transformative journey with an msc in facial aesthetics and cosmetology in india . Delve into the intricate world of beauty and rejuvenation, guided by expert faculty and …
a
a_vlasovApril 14, 2024, 1:41 p.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел Дорофеев
Павел ДорофеевApril 14, 2024, 9:35 a.m.
QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
f
fastrexApril 4, 2024, 11:47 a.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…

Follow us in social networks