Jan. 8, 2016, 11:53 a.m.

Qt

HotKey, QKeySequence, Qt, RegisterHotKey, WinAPI, горячие клавиши

QKeySequence very different from the sequence of hotkeys in WinAPI . QKeySequence actually is a string in which the separator hotkeys are "+" sign, as well as the sequence ", " , if several sequences. Then, as in WinAPI there are modifiers Alt, Ctrl, Shift, which are represented by an unsigned integer type, and hot key, which is represented by the code keypad.

Let us research the option, when there is one sequence in QKeySequence and it is necessary to register as a global hotkey in WinAPI. To this end, we agree that QKeySequence as as a modifier will have only the Ctrl, Alt, Shift , and as hot keys one of the letters of the English alphabet.

Next to parse QKeySequence write two functions:

  • unsigned int winKeyMod(QKeySequence) - which will return an integer combination of modifiers;
  • char winHotKey(QKetSequence) -which will return the code of the hot key.

Modifiers Alt, Ctrl and Shift option in the bit values have 0b00000001 , 0b00000010 and 0b00000100 respectively, so the logical OR any number of data addition will give the required number of combinations. Hence it is necessary in the method winKeyMod , identify modifiers of the sequence and if any one of the modifier to be added that the method returns.

Jan. 4, 2016, 10:41 a.m.

QML

анимация, material design, Android, Qt, QML

QML does not provide animation interactions clicks Material Design Style for Android by default, but is easily adjusted with the Rectangle primitive. Animation is to one parent, Rectangle, when clicked, you need a second child Rectangle object to stretch the entire area of the parent. At the same time the child object will stretch for a certain time and will appear as an expanding circle, but it will not go beyond its parent.

For clarity, create a list of items, which will produce clicks. To track clicks is used area MouseArea, which will be monitored by the interaction of several signals:

  • onClicked - the signal will stop the animation and the result of the interaction performed with the list;
  • onPressed - when the signal is pressing need to run an animation preset coordinates animated object Rectangle.
  • onReleased - you need to stop the animation when you release the list item;
  • onPositionChanged - when you change the position of the field also need to stop the animation.

To make the animation used PropertyAnimation object. This site is chosen goal of animation, and a list of properties that will be subject to change. In the case of animatable object Rectangl, it is necessary to expand the circle, for that increase the properties width, height and radius with the same value. In order to completely fill the parent object properties will exhibit a finite amount three times greater than the width of the parent element.

Another important property is the parent element:

clip - activating this property (true), we cut the child elements of the object, so that they do not go beyond the boundaries of the parent element.

Jan. 3, 2016, 11:35 a.m.

Qt

Qt, HotKey, RegisterHotKey, UnregisterHotKey, WinAPI, горячие клавиши

To work with global HotKey in Qt5 , there is a virtual method nativeEvent . This method replaces the methods winEvent , x11Event , macEvent of Qt 4.8 .

The especiality in the HotKey to Qt is that if the window is not in focus, that is, it is, for example, will be minimized to the system tray, then registered QShortcut simply will not work. It is therefore necessary to work with the global events from the operating system, that is, go to the realization of the platform-specific code in the application to Qt.

RegisterHotKey

In this example Let us examine the option of working with WinAPI. For this we use the function RegisterHotKey.

BOOL WINAPI RegisterHotKey(
  _In_opt_ HWND hWnd,
  _In_     int  id,
  _In_     UINT fsModifiers,
  _In_     UINT vk
);
Jan. 2, 2016, 12:30 p.m.

Qt

Qt, WinAPI, Windows, автозагрузка, автозапуск

As is known, QSettings class allows you to store application settings in the registry of Windows . Due to this possibility, and a good knowledge of your Windows registry, you can add an application to autostart, or remove it from there, through, for example, the application settings dialog. You can use the checkbox, and if it is marked, then by clicking on the button in the confirmation dialog box to write an application to the startup, otherwise, remove it from the startup.

In any case, it all comes down to the two actions.

Write an application to autostart

#ifdef Q_OS_WIN32
    QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
    settings.setValue(APPLICATION_NAME, QDir::toNativeSeparators(QCoreApplication::applicationFilePath()));
    settings.sync();
#endif
Dec. 27, 2015, 9:09 a.m.

Qt

QCustomPlot, QDateTime, Qt, время, график

QCustomPlot Library has the ability to charting the scale of time, which is useful in analyzing the data, which change over time. To do this, you need to install a signature style to the time axis as QCPAxis::ltDateTime. And then set the date and time format. That is, it is possible to display on the axes or the date or time, or simultaneously do both, depending on what you specify formatting. Formatting Rules for QCustomPlot used are the same as for QDateTime , QDate , QTime , classes.

Time coordinate is transmitted in the form of a double number that starts the countdown in seconds from time 1970-01-01T00:00:00 . What to consider when plotting.

I propose to write an application that will build a pseudo-random schedule of income and rubles according to the current time coordinate. At the same time the schedule will be to communicate, that is, zoom and remove it, and move, but only on the horizontal axis. That is, the height of the graph display will not change. Also, we make it possible to change the time format in the coordinate dependence of the visible area of ​​the chart for the time axis. That is, if the visible part of the graph in less than one day, the time-axis signature format will be as follows: hh: mm. Otherwise, the format is " dd MMM yy ".

Building a graph

We create a project and connect it to the library QCustomPlot . Modifications will be subject only mainwindow.h and mainwindow.cpp files. New files will not be added.

Dec. 24, 2015, 10:27 a.m.

QML

Qt, QML, window, Quick, Controls, QtQuick

One of the articles had a chance to answer the question the reader how to implement switching between windows in Q t, so that when you change an inactive window hidden. At the touch of a button opens a second window, and the first closing. And switch back the same way.

Now we ask the same question, but with regard to QML. So, let's see how to implement it on the QML.

Project structre

  • question4.pro - profile project, the default is created and does not change;
  • main.cpp - the main source file, the default is created and does not change;
  • main.qml - qml main file to the main application window;
  • AnotherWindow.qml - type secondary windows project.

AnotherWindow.qml

Explanation of code begin with a secondary application window, since the transmission of information on the button is pressed to open the main application window is realized by a signal. And it is more convenient to describe this moment in the beginning, before proceeding to the main application code.

Dec. 23, 2015, 12:07 p.m.

Qt

Qt, QVector, двумерный, одномерный, массив

Class QVector relates to a container class, and provides access to the items on the index, as well as a number of additional methods for ease of operation.

QVector instance of the class is essentially a one-dimensional array of objects. If you want to set as a vector of two-dimensional array, you can create an instance of a QVector , which will contain other instances QVector .

One-Dimensional array using QVector

For starters keep in Vector-dimensional array of type int:

QVector <int> myVector;

int massive[4] = {1, 2, 3, 4};

for(int i = 0; i < 4; i++)
{
    myVector.push_back(massive[i]);
    qDebug() << "Value " << i << ": " << myVector.value(i);
}

And look at the output qDebug() :

Value  0 :  1
Value  1 :  2
Value  2 :  3
Value  3 :  4
Dec. 23, 2015, 9:36 a.m.

Qt

bmp, jpg, pdf, png, QCustomPlot, Qt, сохранение, файл

In a previous article on working with QCustomPlot was an example of the use of this library. But after the schedule is built, it may be necessary to make its preservation as a graphic file. QCustomPlot Library already provides methods necessary for this. All you need to do - is to create a file which will be saved and pass the path to the file in one of the methods to save the image.

Methods for saving images

saveRastered(const QString &fileName, int width, int height, double scale, const char *format, int quality)
saveJpg(const QString &fileName, int width, int height, double scale, int quality);
savePng(const QString &fileName, int width, int height, double scale, int quality);
saveBmp(const QString &fileName, int width, int height, double scale);
savePdf(const QString &fileName, bool noCosmeticPen, int width, int height, const QString &pdfCreator, const QString &pdfTitle);

saveRastered

It is a fundamental method for methods: saveJpg , savePng , saveBmp . So he called in all of these methods. Inside the method saveRastered QPixmap instance is created, through which the image is saved from QCustomPlot widget. For this method, you can specify the type of file to be saved. Then the remaining three methods simplify work and just write code, canceling the need to specify the file type.

savePdf

This method stands alone and does not use QPixmap , and runs through QPrinter . Although the use of logic in the minimum variant is similar to the rest of the methods.

Dec. 18, 2015, 11:30 a.m.

Qt

Qt, QWebView, ssl, webkit, браузер

Note: The lesson is deprecated. With version Qt5.6 must use WebEngine

Well, who among us does not want to write your browser? Come on, do not deny it thought about the browser exactly were. So, the Qt has QWebView class that allows you to work with webkit browser engine, which is written chromium, and, accordingly, chrome and many other browsers. Therefore, practical use of a dozen lines of code, you can make an application that can display a page of the website.

Thus, the application will be as follows. There is an address bar QLineEdit and a widget QWebView . When you enter a website address in the address bar and pressing Enter key will start getting the site and display it in QWebView . When you click on the link in the link address will be displayed in the address bar and a new page will be loaded in the widget.

Project structure for work with QWebView

  • QWebViewExample.pro - the profile of the project;
  • main.cpp - the main project source code file;
  • mainwindow.h - header file of the main application window;
  • mainwindow.cpp - file source code of the main application window;
  • mainwindow.ui - form the main application window.
Dec. 13, 2015, 10:58 a.m.

Qt

QNetworkAccessManager, Qt, http, скачивание файла

To work with a network other than using QTcpSocket or QUdpSocket classes can use QNetworkAccessManager. This class provides the functionality to send requests across a network and get answers and easy to work with the HTTP protocol.

Therefore I propose to write an application that will allow download xml-file from the website and write it to a file on your PC.

Application logic is as follows:

  1. Download file;
  2. Write it on a local drive at the following path C:/example/file.xml;
  3. Read the recorded file and display the data in QTextEdit.

Project structure for work with HTTP

The project structure is as follows:

  • DownloadHttp.pro - the profile of the project;
  • main.cpp - the main file of the application;
  • widget.h - header file of the application window;
  • widget.cpp - file source code of the application window;
  • downloader.h - class header file for downloading the file;
  • doqnloader.cpp - class source code file to download the file.
Looking for a Job?
14,000.00 руб. - 40,000.00 руб.
Разработчик Qt
Annino, Moscow Oblast, Russia
5,000.00 руб. - 15,000.00 руб.
Дизайнер
Moskovskiy, Moscow, Russia
25,000.00 руб. - 30,000.00 руб.
Разработчик Qt/C++
Barnaul, Altai Krai, Russia

For registered users on the site there is a minimum amount of advertising

A
Aug. 22, 2019, 11:24 p.m.
Aleksandr73

Qt - Test 001. Signals and slots

  • Result:47points,
  • Rating points-6
Aug. 21, 2019, 10:23 a.m.
Andrej Ermoshin

C++ - Test 002. Constants

  • Result:58points,
  • Rating points-2
Aug. 21, 2019, 10:15 a.m.
Andrej Ermoshin

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

  • Result:86points,
  • Rating points6
Last comments
Aug. 19, 2019, 7:41 a.m.
Andrej Jankovich

это проблема дистрибутива, попробуйте установить через пакетный менеджер snap Суть проблемы: libQt5Core которая лежит в дистрибутиве требует версию glibc >= 2.25 у вас видимо …
b
Aug. 18, 2019, 6:09 a.m.
bbb116

cqtdeployer /home/aleks/CQtDeployer/bin/cqtdeployer: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by /home/aleks/CQtDeployer/lib/libQt5Core.so.5) linux mint …
D
Aug. 17, 2019, 9:04 a.m.
Damir

github ChekableTView Правой групповая смена значения при перетаскивании левой как обычно.
Aug. 16, 2019, 1:03 p.m.
Evgenij Legotskoj

Потому, что в минуте 60 секунд
Aug. 16, 2019, 12:16 p.m.
Dmitrij

а почему делитель 60000, а не 1000?
Now discuss on the forum
Aug. 24, 2019, 7:21 a.m.
Evgenij Legotskoj

Не помню, давно уже с QML не работал, по-моему, обычно пишет в консоль, что не находит файл. В любом случае какую-то ошибку в консоль выкидывает. Но если честно, если у вас проект будет ак…
BG
Aug. 24, 2019, 4:27 a.m.
Brjus Gliff

Спасибо, вначале в документации было не понятно что к чему, теперь разобрался
I
Aug. 21, 2019, 8:36 a.m.
Intruder

Александр, мне не нужно перебирать. Вы говорите правильно, сначала я написал избыточный код просто не подумав. Задача такая, мне нужно просто переложить из QMap в атрибуты xml тега все, что там …
Aug. 21, 2019, 3:16 a.m.
nayk1982

Если Вы разрабатываете какую-то универсальную утилиту, которая вообще не привязана к логике, тогда как вариант: 1. Получить список таблиц через QSqlDatabase::tables 2. Для каждой табли…
EVILEG
About
Services
© EVILEG 2015-2019
Recommend hosting TIMEWEB