qgraphicsitem

Connecting signal to slot between classes in PyQt

筅森魡賤 提交于 2019-12-04 22:13:12
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, QPushButton) class TicTacToe(QGraphicsItem): def __init__(self): super(TicTacToe, self).__init__() def

restrict movable area of qgraphicsitem

主宰稳场 提交于 2019-12-04 07:26:52
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. 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 * parent = 0); protected: virtual QVariant itemChange ( GraphicsItemChange change, const QVariant & value ); };

How to save a QGraphicsItem QList to a file and then read it? Qt c++

狂风中的少年 提交于 2019-12-04 04:48:00
问题 I have a list that contains QGraphicsItem. This list allows me to draw lines. I looked in the documentation but I did not see how can we save the points in a file? Then read the points of the file to be able to display them? Here is my code : QList<QGraphicsItem *> graphicsitemList; for (int i=0 ; i<graphicsitemList.size(); i++ ){ for (int j=0 ; j <4; j++){ this->scene->addLine((float)graphicsitemList[i]->scenePos().x(), (float)graphicsitemList[i]->scenePos().y(), (float)graphicsitemList

Pyside2 How can i move box?

为君一笑 提交于 2019-12-04 04:15:42
问题 I want to move my SimpleItem object if I move mouse pressing left button. I have successed getting the position of mouse cursor if I press the object. but I have no idea how to move the item to that position. Could you help me? import sys from PySide2 import QtGui, QtWidgets, QtCore class SimpleItem(QtWidgets.QGraphicsItem): def __init__(self): QtWidgets.QGraphicsItem.__init__(self) self.location = 1.0 def boundingRect(self): penWidth = 1.0 return QtCore.QRectF(-10 - penWidth / 2, -10 -

How to use itemChange from QGraphicsItem in Qt

﹥>﹥吖頭↗ 提交于 2019-12-03 16:26:29
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 QGraphicsItem::itemChange() but I don't know how to use it in my case. As others have already noted, you need

Find screen position of a QGraphicsItem

感情迁移 提交于 2019-12-03 11:27:09
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). I know the selected (focussed) item, I know the view which displays the scene. So my question is: What

Fixed QGraphicsItem position, without changing behaviour of other QGraphicsItems in scene

时光怂恿深爱的人放手 提交于 2019-12-02 01:05:03
问题 This question is related to: Forcing QGraphicsItem To Stay Put I'd like to have a QGraphicsItem on a fixed location when moving around in the scene. The suggested solution is to override the void paintEvent(QPaintEvent*) of the sub-classed QGraphicsView . void MyGraphicsView::paintEvent(QPaintEvent*) { QPointF scenePos = mapToScene(0,0); // map viewport's top-left corner to scene myItem->setPos(scenePos); } However, the problem is that I want everything else in the scene to stay intact, i.e.

Forcing QGraphicsItem To Stay Put [duplicate]

眉间皱痕 提交于 2019-12-01 15:59:06
问题 This question already has an answer here : Draw an item in a static location relative to the QGraphicsView (1 answer) Closed 6 years ago . I have a QGraphicsScene that is filled with QGraphicsItems , and the user is able to pan and zoom around to inspect all of the various QGraphicsItems . However, I would like to have a QGraphicsTextItem label that always stays put at the top left of the screen. Ignoring the zooms is easy, as I can just setFlags(QGraphicsItem::ItemIgnoresTransformations) ,

Detect when mouse enter QGraphicsItem with button down

怎甘沉沦 提交于 2019-11-30 15:50:31
问题 I want to detect when the mouse cursor moves in over a QGraphicsItem while a mouse button is pressed, i.e. the button is pressed before the mouse enters the item. My first idea was to use hoverEnterEvent , but it doesn't seem to trigger when the left mouse button is pressed. My other idea was to use dragEnterEvent , but it doesn't seem to trigger at all (even though I have used setAcceptDrops(True) . What is the best way to detect when the cursor moves on top of an item and the mouse button

Why does QGraphicsItem::scenePos() keep returning (0,0)

橙三吉。 提交于 2019-11-30 15:19:59
问题 I have been toying with this piece of code: QGraphicsLineItem * anotherLine = this->addLine(50,50, 100, 100); qDebug() << anotherLine->scenePos(); QGraphicsLineItem * anotherLine2 = this->addLine(80,10, 300, 300); qDebug() << anotherLine2->scenePos(); Where the this pointer refers to a QGraphicsScene . In both cases, I get QPointF(0,0) for both output. From reading the document, I thought scenePos() is supposed to return the position of the line within the scene, not where it is within its