qgraphicsscene

Add ports to the QGraphicsPixmapItem object

余生长醉 提交于 2019-11-30 20:28:41
问题 I've created something like this. I have created a QGraphicsPixmapItem object that I can add to QGraphicsView. I want to add ports to these objects I created. And I want to make connections between these ports and the objects I have created. I don't know how to do it. can you help me ? my code class Part(QGraphicsPixmapItem): def __init__(self, name): super().__init__() self.name = name self.setFlags(self.ItemIsSelectable | self.ItemIsMovable | self.ItemIsFocusable) self.label = QLabel(

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

How to use QPainter on QPixmap

℡╲_俬逩灬. 提交于 2019-11-30 12:37:27
I'm a newbie to Qt/Embedded. I want to use QPainter to draw stuff on a QPixmap , which will be added to QGraphicsScene . Here is my code. But it does not show the drawings on the pixmap. It shows only the black pixmap. int main(int argc, char **argv) { QApplication a(argc, argv); QMainWindow *win1 = new QMainWindow(); win1->resize(500,500); win1->show(); QGraphicsScene *scene = new QGraphicsScene(win1); QGraphicsView view(scene, win1); view.show(); view.resize(500,500); QPixmap *pix = new QPixmap(500,500); scene->addPixmap(*pix); QPainter *paint = new QPainter(pix); paint->setPen(*(new QColor

Is this PyQt 4 python bug or wrongly behaving code?

我与影子孤独终老i 提交于 2019-11-30 02:57:41
问题 Following code should create the QGraphicsView widget which owns one QGraphicsScene having text inside of it: #!/usr/bin/python import sys from PyQt4.QtGui import * if __name__ == '__main__': app = QApplication(sys.argv) view = QGraphicsView() scene = QGraphicsScene() scene.addText("Hello!") view.setScene(scene) view.show(); sys.exit(app.exec_()) This opens the window, puts the text there, but after I close window - python dumps core and several issues are printed out: (python:5387): Gtk

pyqt add rectangle in Qgraphicsscene

一曲冷凌霜 提交于 2019-11-29 16:18:41
I have a scene like this class Scene(QtWidgets.QGraphicsScene): def __init__(self, parent=None): super(Scene, self).__init__(parent) def mousePressEvent(self, event): print('scene pressed') self.wid = MyRect(event.pos(), event.pos()) self.addItem(self.wid) self.wid.show() I would like class MyRect(QtWidgets.QGraphicsRectItem) with painter, mouse event and so on to be a draggable rectangle. all stuff in MyRect So then I could have many Rectangle to the scene and even after draw line between them and so on (kind of diagram app), but keeping objects related editable options in MyRect, MyLine , ..

Why I can't enlarge a widget added to QGraphicScene by QSizeGrip?

[亡魂溺海] 提交于 2019-11-29 16:17:43
I have added a widget to a graphic scene QGraphicScene through a QGraphicsProxyWidget. To move it I have set QGraphicsRectitem as its parent. The widget is resized with the use of a sizegrip. The first time I create an object I can enlarge it upto some dimension. The second time I can enlarge it less than the first one. The third time less than the second one and so on. It seems to me that it behaves randomly. Why is this happening? Here is the code: void GraphicsView::dropEvent(QDropEvent *event)// subclass of QGraphicsView { if(event->mimeData()->text() == "Dial") { auto *dial= new Dial; //

How to make a ruler on the border of a QGraphicsView

别说谁变了你拦得住时间么 提交于 2019-11-28 11:12:19
问题 I am working on a small .ui project and I am was trying to understand how to properly make a ruler on a QGraphicsView . So when the use sees the image it looks like the following: But if the user needs to zoom-in (or zoom-out) the ruler moves accordingly along with the value of the measurements: Thanks for shedding light on this issue and sor providing any potential example or point to the right direction. 回答1: Create a new class by subclassing QWidget to draw your ruler. Then, set a viewport

Why I can't enlarge a widget added to QGraphicScene by QSizeGrip?

寵の児 提交于 2019-11-28 09:33:35
问题 I have added a widget to a graphic scene QGraphicScene through a QGraphicsProxyWidget. To move it I have set QGraphicsRectitem as its parent. The widget is resized with the use of a sizegrip. The first time I create an object I can enlarge it upto some dimension. The second time I can enlarge it less than the first one. The third time less than the second one and so on. It seems to me that it behaves randomly. Why is this happening? Here is the code: void GraphicsView::dropEvent(QDropEvent

pyqt add rectangle in Qgraphicsscene

本小妞迷上赌 提交于 2019-11-28 05:43:26
问题 I have a scene like this class Scene(QtWidgets.QGraphicsScene): def __init__(self, parent=None): super(Scene, self).__init__(parent) def mousePressEvent(self, event): print('scene pressed') self.wid = MyRect(event.pos(), event.pos()) self.addItem(self.wid) self.wid.show() I would like class MyRect(QtWidgets.QGraphicsRectItem) with painter, mouse event and so on to be a draggable rectangle. all stuff in MyRect So then I could have many Rectangle to the scene and even after draw line between

Need QGraphicsScene signal or event for _after_ change

≡放荡痞女 提交于 2019-11-28 01:23:00
I use QGraphicsScene of the Qt framework. Inside the scene I have some QGraphicsItem s which the user can select and move. I would like to have an info label where the current x and y coordinate of the currently moved selection (can consist of many items) is displayed. I have tried with the signal changed of QGraphicsScene . But it is fired before the x() and y() property of the items is set to the new values. So the labels always show the second-to-last coordinates. If one moves the mouse slowly, the display is not very wrong. But with fast moves and sudden stops, the labels are wrong. I need