qgraphicsitem

Connecting signal to slot between classes in PyQt

牧云@^-^@ 提交于 2019-12-06 17:05:45
问题 Aim is to connect a signal of the top class TicTacToe with the QMainWindow class. It throws an error: TicTacToe cannot be converted to PyQt5.QtCore.QObject in this context #!/usr/bin/env python from PyQt5.QtCore import (QLineF, QPointF, QRectF, pyqtSignal) from PyQt5.QtGui import (QIcon, QBrush, QColor, QPainter, QPixmap) from PyQt5.QtWidgets import (QAction, QMainWindow, QApplication, QGraphicsView, QGraphicsScene, QGraphicsItem, QGridLayout, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit,

Save/Load items from a QGraphicsScene

喜欢而已 提交于 2019-12-06 11:24:58
问题 I want to save all items in a QGraphicsScene to a file. When I load the file, I should be able to use them as QGraphicsItems(as before). I keep my items in a QList like QList of QGraphicsItems that i called mItemsOnScreen. I should be able to get back that list when i load the file.How can I save those items to a file on disk. What kind of a file format should i use? And of course how will i read that file back?Please Some Help...And Thank's in advance. I already do this but it save image

PyQt: Moving multiple items with different ItemIgnoresTransformations flags

只谈情不闲聊 提交于 2019-12-06 11:13:04
Sometimes selected items do not move together. This happens in an application with two types of items: "regular items" "handles" with ItemIgnoresTransformations flag (they must keep the same size upon zooming) When they are selected together, and moved by mouse, they are expected to be translated by the same amount (they should move as a whole). It works fine when only "regular items" or only "handles" are moved, but not when both types are selected. Here is a minimal example displaying the problem. It can also be found on sourceforge , together with an enhanced version displaying also some

Only move QGraphicsItem when mouse in specific region

扶醉桌前 提交于 2019-12-06 08:43:44
I'm trying to create something similar to terragens node network view in python using PySide. I subclassed QGraphicsRectItem using this code. class Node(QGraphicsRectItem): def __init__(self,pos): QGraphicsRectItem.__init__(self,pos.x()-100,pos.y()-30,200,60) self.setFlag(QGraphicsItem.ItemIsMovable,True) (...) Which gives this (with some fancy painting): I'd like to implent connecting nodes by dragging the mouse from one small rectangle to another, but this results in moving the whole node. So I don't want the QGraphicsRectItem getting moved when the mouse is pressed inside a small rectangle.

restrict movable area of qgraphicsitem

瘦欲@ 提交于 2019-12-06 02:49:12
问题 Is there a way to restrict the area where a QGraphicsItem like QRect can be moved when setFlag(ItemIsMovable) is set? I'm new to pyqt and trying to find a way to move an item with the mouse, and the restrict it to only vertically/horizontally. 回答1: If you want to keep a limited area you can reimplement the ItemChanged() Declare: #ifndef GRAPHIC_H #define GRAPHIC_H #include <QGraphicsRectItem> class Graphic : public QGraphicsRectItem { public: Graphic(const QRectF & rect, QGraphicsItem *

Qt update() doesn't work

ⅰ亾dé卋堺 提交于 2019-12-06 00:17:55
I have a problem , that update() function in QGraphicsItem doesn't work. What I want to do is , when I move circle , other QGraphicsItem ( in the mean time roundrect ) changes color. This is a example, what I want to do: circle.cpp: void CircleItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { // RoundRect Object RectItem->SetBackGround(); QGraphicsItem::mouseMoveEvent( event ); } RoundRect.cpp: void RoundRectItem::SetBackGround() { ChangeBackground = true; update(); } void RoundRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { QRectF rec =

How to make a QGraphicsItem show the background in a QGraphicsScene?

孤者浪人 提交于 2019-12-05 22:23:01
问题 In a QGraphicsScene , I have a background set with a few QGraphicsItem s on top of it. These graphics items are of arbitrary shape. I'd like to make another QGraphicsItem, i.e. a circle, which when placed over these items will essentially show the background within this circle, instead of being filled with a color. It would sort of be like having a background with multiple layers on top of it in photoshop. Then, using a circular marquee tool to delete all the layers on top of the background

Iterator for elements in QGraphicsScene

两盒软妹~` 提交于 2019-12-05 19:53:52
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 these objects manually (for example in a vector) since this involves additional book-keeping when objects

Resizing and rotating a QGraphicsItem results in odd shape

雨燕双飞 提交于 2019-12-05 08:11:16
I can't understand how scaling and rotation are applied to QGraphicsItem . I need to be able to apply rotation and scaling ( not necessarily keeping aspect ratio ) and I get fully unexpected results. Rotation must be around the item center. I seem to have no problem doing that - yet if I try to debug the bounding rectangle, I get seemingly wrong values. If I don't keep aspect ratio, instead of rotation I get a very weird skew, and I have been struggling for quite a while to find the cause and correct it. I hope anybody can find a solution. For many items - like rectangles - my solution was to

How to use itemChange from QGraphicsItem in Qt

烈酒焚心 提交于 2019-12-05 02:21:53
问题 I have custom ellipse QGraphicsItem class and custom line class. On scene I have let's say two ellipses and connection made between them by a line. Ellipse has a pointer to this line and is movable. My problem is that I dont know how to use itemChange() from QGraphicsItem . I want to make connection which will be changing with ellipse movement. So I want to use itemChange() method to change line coordinates in a way that it always will be in center of ellipse. I read documentation from