qgraphicsitem

How to integrate a custom GraphicsItem into a QML scene?

大兔子大兔子 提交于 2019-12-24 05:36:08
问题 Assume you have created the following custom QGraphicsRectItem in C++: class MyCustomItem : public QGraphicsRectItem { public: MyCustomItem(MyCustomItem* a_Parent = 0); virtual ~MyCustomItem(); // specific methods private: // specific data }; Assume also that you have defined in a QML script an ApplicationWindow : // main.qml import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.0 ApplicationWindow { id: myWindow title: qsTr("My Window") width: 640 height: 480 visible: true }

Iterator for elements in QGraphicsScene

不羁的心 提交于 2019-12-22 10:55:05
问题 I have a QGraphicsScene which contains custom objects (with QGraphicsItem as base class). I can retrieve these objects with: foreach (QGraphicsItem* item, items()) { if (item->type() == CustomItem::Type) qgraphicsitem_cast<CustomItem*>(item).doStuff(...); } Is it possible to write a custom iterator for just this type of objects? I want to be able to use range-based for-loops and algorithms from the STL. for(CustomItem& a : custom_items()) a.doStuff(...); I want to avoid storing pointers to

Find screen position of a QGraphicsItem

感情迁移 提交于 2019-12-21 03:45:12
问题 Use case: This should be a fairly common problem. In a normal QMainWindow with QMdiArea lives an mdiChild with a QGraphicsView. This view displays a QGraphicsScene with QGraphicsItems inside. A right-click at one of these items selects (focusses) the item and opens a context menu, which is conveniently placed at the screen coordinates QGraphicsSceneMouseEvent::screenPos() . This is working as expected. Now I'd like to show the same context menu when the user presses a key (e.g. Qt::Key_Menu).

Using Qt model/view framework to notify QGraphicsItem in a view of user-edit made in another view

我只是一个虾纸丫 提交于 2019-12-20 06:10:00
问题 I am trying to design a multiview application to use Qt's model/view framework so that I can move lots of complex logic out of my QGraphicsItem classes. As shown in the figure below, the application consists of two (or more) views each containing of an identical series of red vertical guide lines A1 , B1 , C1 ... at the same horizontal positions along each view. I'd like to ensure that when the user drags a guide line one view, say from a point A1 to A_1' as shown in the figure above, all

QGraphicsItem doesn't receive mouse hover events

百般思念 提交于 2019-12-19 12:24:35
问题 I have a class derived from QGraphicsView , which contains QGraphicsItem -derived elements. I want these elements to change color whenever the mouse cursor hovers over them, so I implemented hoverEnterEvent (and hoverLeaveEvent ): void MyGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event) { update (boundingRect()); } However, this event handler code is never executed. I've explicitly enabled mouse tracking: MyGraphicsView::MyGraphicsView(MainView *parent) : QGraphicsView(parent) {

Drawing widgets (such as buttons) over QGraphicsView

∥☆過路亽.° 提交于 2019-12-19 04:49:21
问题 How do I draw interactive widgets such as QButtons and Line Edits over a QGraphicsView? For ex, I have selected a region over an image in an image editing app which displays an image with QGraphicsView, and I want to annotate this region with a name. So I want to have a Line edit and two buttons (Cross and Tick) below this rectangular selection. How do I draw these? Sample code would be cool! 回答1: QGraphicsScene has a function addWidget() where you can add a widget to a scene. If you don't

What is the meaning of “the item's view geometry and scene geometry will be maintained separately”?

好久不见. 提交于 2019-12-13 04:43:02
问题 The documentation for the QGraphicsItem::ItemIgnoresTransformations flag says The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item's view geometry and scene geometry will be maintained separately . You must call

Qt tablView with model containg pointer to custom class

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:18:58
问题 I created my custom class (CustomObject), that inherit from QGraphicsItem. I use those object to draw on scene (rectangles, polygons and stuff) and I store pointers to them in QList. Now I need to display all my CustomOBjects in tableView, but there are 2 conditions: When I select and interact with object in tableview - I must be able to interact with "real" CustomObject represented by it (example: I selected obj1 in tableview and click button "delete" or "edit" - and I want to be able to

Rotate QGraphicsPixmapItem results in shear if resizing without keeping aspect ratio

落花浮王杯 提交于 2019-12-13 02:00:23
问题 I am trying to rotate a QGraphicsPixmapItem child. For other QGraphicsItem , rotation and scaling work fine. But for a QGraphicsPixmapItem , if the size does not keep aspect ratio, instead of rotation I get shear. sample code: #include <QApplication> #include <QGraphicsView> #include <QMessageBox> #include <QGraphicsPixmapItem> #include <QFileDialog> int main(int argc, char *argv[]) { QGraphicsScene s; s.setSceneRect(-200, -200, 500, 500); QGraphicsView view(&s); view.show();

Deleting a QGraphicsItem/QGraphicsObject from QGraphicsScene?

泪湿孤枕 提交于 2019-12-13 01:19:47
问题 I have created Qt GUI application. It consists of QGraphicsScene , and items ( QGraphicsItem s) are added to them by pressing or triggering pushbutton s. Each item added to the scene are members of different classes derived from QGraphicsItem . Now, my challenge is to delete an added item off the scene through one of the following mechanisms: 1) Right click an added item, create a context menu, and then use scene->removeItem(addedItem); 2) Double click the item which deletes the item 3)