Sept. 1, 2019, 11:09 a.m.


Добрый день.
С помощью такого класса создаю эллементы в QGraphicsView

class MoveItem : public QObject, public QGraphicsItem
    explicit MoveItem(QObject *parent = 0);
    int id;
    int width, height;

    QRectF boundingRect() const;
July 20, 2019, 9:52 a.m.


Добрый день.
Взял код из этой статьи.
Кочу добавлять эллементы QGraphicsItem не в виде прямоугольника, а в виде картинки.
Попробовал сделать так, но картинка не добавляется.
Скажите пожалуйста, как сделать правильно?

void MoveItem::paint(QPainter *painter, cons…
May 8, 2018, 8:44 a.m.


Необходимо уметь рисовать направленный граф.
В примерах QT нашел проект elasticnodes . Его переделал под свою задачу.
Получилось реализовать создание вершин/стрелок и их выделение/удаление/перемещение. Вот только не получается сделать дугу на самого себя и его область выделения. …
Oct. 22, 2017, 4:54 a.m.


QGraphicsItem, QGraphicsScene, QGraphicsView, Vector Editor, QGraphicsObject

Quite often there are questions in one way or another related to the work of the graphic scene, with custom figures, drawing lines on the graphic scene, and even all sorts of broken lines. And then I remembered about one project that I did as a test task.

Namely, it was a vector editor that can:

  • Create rectangles
  • Change the size of these rectangles
  • Twist the rectangles around the center
  • Fill rectangles
  • Fill rectangles with a gradient
  • Change the width of the outline of a rectangle
  • Set the color of the outline of a rectangle
  • Create lines
  • Specify the width and color of the created line
  • Make broken lines from lines by double clicking by adding points on the line
  • Select all graphic objects and drag them with a handful
  • Save the resulting image to an SVG file, and restore all graphic objects from this file

On the implementation of this project in its time (1.5 years ago), I spent about 36 hours of working time ... now it would take less time.

May 7, 2017, 7:41 a.m.


На QGraphicsScene размещен переопределенный QGraphicsRectItem, в который добавлены с помощью addItem несколько дочерних QGraphicsRectItem. Фильтр событий для child'ов включен (setFiltersChildEvents(True)). По идее, любой клик на child, должен вызывать mousePressEvent у родительского QGraphicsR…

Jan. 17, 2017, 6:17 a.m.


Вот проект. При нажатии на квадрат он меняет цвет. Хотелось бы, чтобы он цвет менял, но не двигался. Мне зафиксировать сцену нужно или что сделать? Может кто-нибудь изменить код, чтобы квадрат не двигался, а лишь изменял цвет.

Dec. 6, 2015, 9:47 a.m.


GameDev, QGraphicsItem, QGraphicsObject, QGraphicsScene, Qt

My attention was drawn to the fact that for working with signals and slots instead of a class inherited from QGraphicsItem and from QObject , you can use a class inherited from QGraphicsObject . Indeed, if a little rummage in the source QGraphicsObject , we find that it is a class inherited from QGraphicsItem and from QObject . That is also used multiple inheritance, but in this case all the bikes have written to us. Therefore, we try to work with this class as an example of the game mechanics.

Specifically, I propose to write a program in which we will move the hero mouse click on the graphic scene, as in any RPG like Diablo.

Project structure for work with QGraphicsObject

  • - the profile of the project;
  • main.cpp - the main source file;
  • widget.h - header file of the application window;
  • widget.cpp - file source code of the application window;
  • customscene.h - customized header graphic scene;
  • customscene.cpp - file source customized graphic scene ;
  • triangle.h - header file of hero class;
  • triangle.cpp - source file triangle class.
Dec. 4, 2015, 12:18 p.m.


figure, QGraphicsItem, QGraphicsScene, Qt, Qt уроки, square, triangle, ооп, Полиморфизм, пример

Polymorphism is one of the paradigms of OOP (Object Oriented Programming). Polymorphism implements the ability to provide base-class properties and methods, the implementation of which is not known for future classes that inherit from this class. That is the base class in this case, has all the necessary methods for the realization of tasks, but the specific implementation of certain methods is assigned to the descendants of the classes. And, as a rule, it is an abstract base class, then there are no objects on it.

For example, it is necessary to implement the program in which it is possible to draw a few geometric shapes with the mouse on the graphic scene , choosing the current figures with the buttons in the application. To do this, you can create several classes, each of which will implement all the necessary functionality, and actually duplicated in each class most of the code, making it more difficult and confusing design. Alternatively, you can create one base class, eg, Figure , which is inherited from QGraphicsItem , and implement all the basic functionality in this class, and then create three classes that will inherit from this class, but to implement them only a method of drawing the figure itself: Romb , Square , Triangle .

In the following figure shows the inheritance logic for the base class Figure. Applied as multiple inheritance class Figure for the implementation work with signals and slots .

Oct. 7, 2015, 11:26 a.m.


QGraphicsScene, Qt, Qt урок, перетаскивание, QGraphicsItem

Let's say that you make an application that will be displayed the elements of the network infrastructure on the graphic scene . The question is how to make the movement of these elements with the mouse, you have to implement drag and drop elements. In other words, take the item with the mouse and exercise his moving to another place graphic scene.

Project Structure

To illustrate an example of creating a new project and add the new class, inherited from QGraphicsItem .

  • - the profile of the project;
  • main.cpp - launch files;
  • widget.h - header of the main window;
  • widget.cpp - file source of the main window;
  • moveitem.h - header graphic element;
  • moveitem.cpp - file source graphic;
  • widget.ui - form the main window.
Sept. 22, 2015, 12:36 p.m.


GameDev, QGraphicsItem, QGraphicsScene, QPainter, Qt, написать игру

Continuing the theme of how to write a play on Qt. Once in past articles a fly was created, that eating apples, it is time to create her enemy. And the enemy flies, as is well known, the spider. Creation of game characters, who will participate in the immediate life of your main character - is not only rendering the animation action and movement, as well as the reactions of the logic on the impact of the player, but also artificial intelligence, in accordance with the logic of which will be determined by the behavior of the game character. Thus, we add to the game a new meaning, not only to eat as many apples, but to survive at any cost.

We define the behavior of the spider in this game. What should he do? Yes, the most common of all the action - to hunt a fly just chasing it on the playing field.

Also add to the game button to start the game process, and pause, and the most important thing to add - it's Game Over.

The enemy flies in the project structure

As is the case with the fly in the structure of the project added an additional class, which will be responsible for the object, which is a spider.

  • spider.h - header file of spider
  • spider.cpp - source file of spider

Hello, Dear Users of EVILEG!!!

If the site helped you, then support the development of the site financially, please.

You can do it by following ways:

Thank you, Evgenii Legotckoi

Dec. 11, 2019, 4:56 p.m.

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

  • Result:50points,
  • Rating points-4
Dec. 10, 2019, 8:06 a.m.
Anastasija Troschenkova

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

  • Result:60points,
  • Rating points-1
Dec. 10, 2019, 8:02 a.m.
Anastasija Troschenkova

Qt - Test 001. Signals and slots

  • Result:73points,
  • Rating points1
Last comments
Dec. 9, 2019, 3:41 a.m.
Evgenij Legotskoj

Эта ошибка invalid use of incomplete type ‘class Ui::AnotherWindow’ обычно говорит о том, что не найдено определение класса или структуры. Типичная проблема - не подключён заголовочны…
Dec. 9, 2019, 3:36 a.m.
Nikolaj Batmanov

Ну, не настолько со мной всё полхо...))) Вроде бы. Я ж кнопки отрисовываю.
Dec. 9, 2019, 3:14 a.m.
Evgenij Legotskoj

Добрый день. У вас ui файлов по ходу нет. UI файлы используются для вёрстки в графическом дизайнере.
Dec. 9, 2019, 3:05 a.m.
Nikolaj Batmanov

Здравствуйте! Полностью скопировал ваш пример к себе, чтобы разобраться. А он не хочет запускаться, дает ошибку: invalid use of incomplete type ‘class Ui::AnotherWindow’ ui(new Ui…
Dec. 8, 2019, 7:23 a.m.
Evgenij Legotskoj

У меня здесь есть одна старая статья с примером векторного редактора. Там есть ответы на ваши вопросы. Поизучайте Qt/C++ - Урок 072. Пример векторного редактора на Qt QGraphicsItem, QG…
Now discuss on the forum
Dec. 11, 2019, 8:27 a.m.
Maciej Urmański

Thank you! Now works, and this is solution. num_embed = Embed.objects.filter(added_by=recipe.added_by).count()
Dec. 11, 2019, 8:12 a.m.

Так работает. Взял этот пример void MainWindow::on_pushButton_4_clicked() //фото определение лица{ // Load Face cascade (.xml…
Dec. 10, 2019, 4:14 a.m.
Timur Dosov

Спасибо, работает. А ещё вопрос: как загрузить страницу с динамической подгрузкой контента по скроллингу? Например - []. Пока делаю через костыль - QApplication::s…
Dec. 9, 2019, 7:16 a.m.

Я сделал простой вывод текста по испусканию сигнала... Чего не хватает программе?) Python: # системные библиотекиimport cv2import numpy as npimport sysimport threading# PyQt б…
Dec. 8, 2019, 4:11 p.m.
Semen Kosandjak

інтерфейс qt, приклад того додаю на малюнку, я натискаю на кнопку і у мене з'являється 2 текст лайну в які я вводжу значення, тобто в 1 цифри,у другому випадку це літери, тобто c++, без графічно…
© EVILEG 2015-2019
Recommend hosting TIMEWEB