Advanced search
Evgenij LegotskojNov. 11, 2015, 7:25 p.m.

QMLQML - Lesson 015. Development QML Data Mapper – Analog of QDataWidgetMapper

QML, Qt, QDataWidgetMapper, mapper, QMLDataMapper

In the process of transferring a GUI softiny with QWidgets on QML QDataWidgetMapper found no analogue for QML. This fact was somewhat spoiling the mood. But there was nothing, but to look for other ways to implement or make their full version of this, your Qml Data Mapper.

Nevertheless, searching on the web expanses yielded the results as an example in 2011 by Nokia developers to implement the SQL Widget Mapper for BlackBerry based on Cascades (framework for native development on QML Qt under BlackBerry, respectively). By evening meditation on the present example was able to saw through the code for the current QML Qt, which is quite nice to feel like when working under the Desktop, and when running under Android, (cross-platform no matter how how).

To demonstrate the QML Data Mapper will write an application that works with the SQLite database. Each time an application writes a few lines in a database, from which data are collected using a data model to inherit from QSqlQueryModel and displayed in QML TableView. The main window of the application there is a button, pressing that cause, which displays information on the first row of the table dialog. When you double-click on one of the rows in a table is also called a dialog box, but the information on this line. Also present button in the dialog box to scroll through the information from the table.

Evgenij LegotskojNov. 10, 2015, 7:06 p.m.

QMLQML - Lesson 013. Positioning with Anchors

anchors, left, right, bottom, top, centerIn, Qt, QML

In addition to the more traditional Grid , Row , and Column , Qt Quick also provides a way to layout items using the concept of anchors . Each item can be thought of as having a set of 7 invisible "anchor lines":

  • left;
  • horizontalCenter;
  • right;
  • top;
  • verticalCenter;
  • baseline;
  • bottom.

The baseline (not pictured above) corresponds to the imaginary line on which text would sit. For items with no text it is the same as top .

Evgenij LegotskojNov. 9, 2015, 3:03 p.m.

QMLQML - Lesson 012. Data transmission from the TextInput in ListView (Model / View)

ListView, ListModel, TextInput, Model, Delegate, QML, Qt, Android, View

Working with the ListView in QML is a fairly common aspect in the development of Android applications, since many applications have in their functional building lists of data, records, settings, etc. It is also true in developing a Desktop applications with QML principle would be the same for both platforms.

For its consideration of the transfer of information in the list offer carefully consider the following scenario of interaction with the ListView .

The principle of view data in the ListView

ListView object has two important properties:

  1. delegate - which determines the appearance of a single element ListView
  2. model - which placed the data of each element

The transmission model can be used ListModel object that contains the data for each item in the list. The data assigned to variables that have been assigned to certain properties of the objects in the delegate. In the figure below has two delegate objects Text, text properties which the variables text_first and text_second assigned. These variables determine which will be substituted data from each ListElement in ListModel . As can be seen from the figure, each ListElement has two properties, the name of which is identical to the variables that are assigned to the delegate. In fact, these variables are roles, which put a value of ListModel . So we get ListView with text fields, which are filled with the data that have been made in each ListElement in ListModel .

Evgenij LegotskojNov. 6, 2015, 7:17 p.m.

QMLQML - Lesson 014. GridLayout QML – Positioning of elements

GridLayout, Qt, QML, ячейка, cell, row, column

A short note, born out of the question of one of the regular readers of the site. When developing the application interface under QML for positioning objects in the GridLayout is necessary to use the functionality of embedded properties Layout. Such as:

  • Layout.row - indicates the line where the object is located;
  • Layout.column - indicates the column in which the object is located;
  • Layout.rowSpan - indicates how many lines should be stretched object;
  • Layout.columnSpan - indicates how many columns should be stretched object;
  • Layout.minimumWidth - the minimum width of an object in a layer;
  • Layout.minimumHeight - the minimum height of the object in a layer;
  • Layout.preferredWidth - the preferred width of the object in a layer;
  • Layout.preferredHeight - the preferred height of the object in a layer;
  • Layout.maximumWidth - the maximum width of the object in a layer;
  • Layout.maximumHeight - the maximum height of an object in a layer;
  • Layout.fillWidth - filling in width;
  • Layout.fillHeight - filling height;
  • Layout.alignment - alignment layer;
Evgenij LegotskojNov. 5, 2015, 2:26 p.m.

QMLQML - Lesson 011. Data transmission from QML QSqlQueryModel in the TableView

QML, SQL, Qt, DataBase, QSqlQueryModel, TableView

To represent database tables in the development TableView using QML You can use a class inherited from QSqlQueryModel . To do this, in the inherited class to define a method that would establish the respective roles of the table columns to the corresponding columns in the TableView, defined in the QML , which also indicates the roles of each object TableViewColumn , that is, for each column. You will also need to override a method QVariant data(...) const , which returns the data for the table cells. In this case, the information will be returned in accordance with certain roles columns of the table.

The project structure to work with TableView

The project consists of the following files:

  • - the profile of the project;
  • database.h - header to create and initialize the test database;
  • database.cpp - file source code to create and initialize the test database;
  • model.h - header data model file;
  • model.cpp - file source data model;
  • main.cpp - the main source file;
  • main.qml - qml file TableView.
Evgenij LegotskojNov. 2, 2015, 1:55 p.m.

QMLQML - Lesson 010. Access to child objects in TabView

Qt, QML, reference error, TabView

The structure of objects in Qml is a tree in which to access the properties of objects underlying level please refer to the original object, then select the child object and select the child object property to which you want to access.

But in the case TabView this approach does not work, because the objects tabs added dynamically, so you need to access the tab on its index, pick up an object from the item and find it of interest to us a child object in this item also on the index. And then get access to the property of interest to us. It is also recommended to note that in this case, the code does not work completion QtCreator .

And most likely you will get an error as follows:

ReferenceError: 'something' is not defined

Evgenij LegotskojNov. 1, 2015, 11:39 p.m.

QMLQML - Lesson 008. How to work with system tray (QSystemTrayIcon)

QSystemTrayIcon, Qt, QML

When moving the application interface from Qt / C ++ to Qt / QML my hands reached and application icons in the system tray. The aim was to put an icon in the System Tray from C ++ to QML, partially or completely. The first option, which I realized, was a wrapper around QSystemTrayIcon with QMenu using a system of signals and slots . The solution is quite logical, given that in QML is not a facility, like MenuBar to System Tray. So we do a wrapper, which can interact in QML layer.

After the wrapper was implemented, I had the opportunity to consult with the programmer of Wargamming  - Constantine Lyashkevich , who recommended me to pay attention to what QML can have access not only to the signals and slots, and the parameters of the Q_PROPERTY , who also were in the class QSystemTrayIcon , that is, in fact it was only possible to register this class as the type layer in QML and try to write almost all the code on the QML. I checked the board and talked about by Constantine. As a result, he became interested in this problem and we spent the evening entertaining hour of attempts and jointly stuffed QSystemTrayIcon maximum in QML.

So in this article you will see two implementations to work with an icon in the system tray.

The resulting application will minimize to the System Tray by clicking the icon in the system tray, as well as by pressing the close button. But only in the event that will be active the special checkbox to control the folding process of the application window to the system tray, if the checkbox is not enabled, the application will be closed. Also, the application can be closed with an active checkbox menu item in the system tray icon.

Evgenij LegotskojOct. 26, 2015, 11:25 p.m.

QMLQML - Lesson 007. ListView. Dynamic creation and deletion of elements

Android, ListItem, ListModel, ListView, QML, Qt

I have already told in the article about the creation of dynamic widgets to Qt , how to create and delete buttons dynamically, as well as how to interact with them. And there used Vertical Layout, a case we can use QML ListView Qml, both similarly used when programming in Java for Android. That, incidentally, is also applicable when programming in Qt for Android.

The article about the dynamic creation of widgets used for example QButton class objects. This article will use the objects Button Qml, which customization was discussed in the following article . But the key will be placed in the ListView Qml.

Project structure for ListView Qml

This time dispense project created by default and even without the designer interface. Especially because at the time of this writing, not all parameters can be set in the designer. A following project structure:

  • - the profile of the project;
  • deployment.pri - deploy rules file on the target platform;
  • main.cpp - the main application startup file;
  • main.qml - qml file with the original program codes
Evgenij LegotskojOct. 24, 2015, 11:37 p.m.

QtQt/C++ - Lesson 038. Switching between windows in the Qt

QMainWindow, QWindow, переключение

Recently, a subscriber asked me for help on the issue, the answer to which he was looking for on the Internet. I do not have much free time, but it seems the stars have converged so that time was the question from the category of those that have already had some experience.

So, the crux of the matter was that, in order to arrange to switch between the main window and the secondary. Yes thereby to shut the open window and the second window opened instead. That is to say that at the touch of a button in the main window to open another window and close the main window at the same time. In this second box contains a button, clicking on which opens the main window and the second window is closed, respectively.

Project structure

The project structure is characterized by the presence of an additional class of default, which would be responsible for the secondary window.

  • anotherwindow.h - header secondary window;
  • anotherwindow.cpp -  source file of secondary window.
Evgenij LegotskojOct. 24, 2015, 1:30 p.m.

QMLQML - Lesson 009. Scalable interface in Qt QML Android

Android, Desktop, QML, Qt, scalable, scalable interface, масштабируемый интерфейс

If we talk about Scalable interface, that is scalable interfaces for developing applications on Qt, this is the main problem is that you need to create an interface that will be read perfectly on all screens, whether computer screen or a smartphone screen.

Parameters of the GUI, such as the width and height are specified in pixels in Qt , but with the same screen resolution on your computer and on your phone (for example, 1366 x 768 pixels) get completely different results. On your computer, button size 40 by 60 pixels would be convenient, I would even say a large, and on the screen of the smartphone is already on it will be difficult to get a finger.

Therefore the development of a single application interface for multiple platforms and screens must be some way to solve the interface problem of scalability.


Let me recommend you the excellent hosting on which EVILEG is located.

For many years, Timeweb has been proving his stability.

For projects on Django I recommend VDS hosting

View Hosting
  • pstMem
  • Nov. 27, 2020, 10:22 p.m.

C++ - Тест 003. Условия и циклы

  • Result:64points,
  • Rating points-1
  • qwerty
  • Nov. 27, 2020, 6:29 p.m.

C++ - Тест 003. Условия и циклы

  • Result:42points,
  • Rating points-8

C++ - Test 002. Constants

  • Result:25points,
  • Rating points-10
Last comments

QML - Lesson 016. SQLite database and the working with it in QML Qt

Помогите, пожалуйста. У меня похожая задача, но я в qml слой долен передать не чистый запрос, а со сложной обработкой, поэтому у меня в С++ слое есть иерархия классов, которая имитирует бд и зап…
  • eviza
  • Nov. 16, 2020, 3:32 p.m.

Qt/C++ - Tutorial 083. Creating a dynamic library and connecting it to another project

здравствуйте! при компиляции библиотеки выскакивает окно особая программа( не удалось найти программу, укажите путь к ней), и в папке debug создается файл .dll, а .lib нет. подскажите…

Data encryption by RSA algorithm in Qt with public and private keys without binding to OpenSSL

Библиотека подключилась нормально, только на выводе из первого примера выходит пустое сообщение, вместо "test message" просто "". Никаких ошибок не выдает.

Qt WinAPI - Lesson 002. How to make win installer for Qt apllication?

Можно ли как-то однозначно (не проверяя) выяснить, запустится ли программа в windows 7? И как быть с разрядностью уже и просто в w10 (32\64)?

Django - Tutorial 036. How to add authentication through social networks. VKontakte

Возможно, автор прочитает. Делал авторизацию с помощью ВК по книге Дронова. Выдает ошибку "Backend not found". Стал гуглить, нашел вашу статью, вроде почти то же самое (оно и понятно, документа…
Now discuss on the forum
  • solmik
  • Nov. 27, 2020, 11:44 p.m.

Обращение к ячейке таблицы

Спасибо, разобрался, у меня получилось немного не так, таблица создавалась в Qt Creator, рядом с таблицей поставил кнопку и вот слот обработки сигнала этой кнопки: void MainWindow::on…

Установка OpenSSL с QT Windows

К продолжению темы в QT 5.15.1 появились уже готовые libeay32.dll и ssleay32.dll на машине сборки все работает. На целевую машину в папку с exe подкидываю libeay32.dll и ssleay32.dll результата…

QStyledItemDelegate не изменяются данные

Привет. Редактирую ячейку, нажимаю enter, либо просто кликаю на др место, но введенные данные возвращаются к тем, что были до редактирования. К примеру, меняю дату: 01.01.2000 было, редактирую 0…

Отправка JSON


Разный масштаб в формах и при запуске

Сврестайте все в один лэйаут (Выбирите окно и нажмити сверху на голубой квадратик из 9 голубфх квадратиков)
© EVILEG 2015-2020
Recommend hosting TIMEWEB