qgraphicsview

How to enable Pan and Zoom in a QGraphicsView

99封情书 提交于 2019-12-31 06:58:28
问题 I am using python and Qt Designer to implement loading tiff images and to enable Pan and Zoom on some mouse event (wheel - zoom, press wheel - pan). I was looking into some options and classes that can work with images etc, and so far I have found: QGraphicsScene, QImage, QGraphicsView I have three classes (just testing) ViewerDemo which have QGraphicsView element: """description of class""" # Form implementation generated from reading ui file 'GraphicsViewdemo.ui' try: _fromUtf8 = QtCore

Bearing Formula calculations in GraphicsScene producing erratic results

a 夏天 提交于 2019-12-31 06:49:26
问题 I'm getting very unpredictable results using basic bearing calculations. What I need to happen is that as I draw these lines based on the angle of the dial, the lines need to uniformly get drawn into the center of the view. Right now, I'm just getting erratic results and I'm hoping someone here can elucidate my issues. Best to see the results for yourself. Only thing I did to the mainwindow.ui form was: set centralWidget to Width: 530, Height: 633 add a QGraphicsView display widget to X: 8, Y

How do I keep drawing on image after window resize in PyQt?

为君一笑 提交于 2019-12-31 04:49:06
问题 I have written a code to draw a rectangle on an image in a QGraphicsView but if I resize the image, for example full screen, the position of the rectangle becomes misplaced. Is there any way to fix this? I think one possible solution is to align the image every time in top left corner but I cannot give 2 arguments in setAlignment() . Here is the code:(the buttons are just for show atm) class MyWidget(QWidget): def __init__(self): super().__init__() self.b1 = QPushButton('Next Image') self.b2

MousePressEvent, position offset in QGraphicsView

倾然丶 夕夏残阳落幕 提交于 2019-12-30 08:38:31
问题 I've some difficulties with QGraphicsView and QGraphicsScene . When I zoom/unzoom in the scene and create items with mousePressEvent, I have an offset in the position. How can this be avoided? event.pos() seems to be the problem.. from PyQt4 import QtCore, QtGui class graphicsItem (QtGui.QGraphicsItem): def __init__ (self): super(graphicsItem, self).__init__() self.rectF = QtCore.QRectF(0,0,10,10) def boundingRect (self): return self.rectF def paint (self, painter=None, style=None, widget

Selecting item from QGraphicsScene in PyQt5

自作多情 提交于 2019-12-25 18:53:32
问题 I am loading image using QGraphicsView and QGraphicsSCene. I have multiple RectItems in QGraphicsScene. Code is given below; def load_image(self,image_item): rect_list = [[20,30,70,35],[50,100,60,100],[410,450,60,100]] self.pic = QPixmap(str(image_item.text())) self.scene = QGraphicsScene(self.centralWidget) self.brush = QBrush(Qt.BDiagPattern) self.pen = QPen(Qt.red) self.pen.setWidth(2) self.load_view = self.scene.addItem(QGraphicsPixmapItem(self.pic)) for rect in rect_list: self.rect_item

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

拥有回忆 提交于 2019-12-24 23:54:24
问题 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

A change in eventFilter function causes weird QGraphicScene behavior

只愿长相守 提交于 2019-12-24 15:00:06
问题 I have a Qt program with a QGraphicScene inside a QGraphicsView on top of QMainWindow. The events are handled by the QMainWindow using an eventFilter function. The function body looks similar to this code: bool Window::eventFilter(QObject *, QEvent *event) { QEvent::Type type = event->type(); if (type == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); switch(keyEvent->key()) { case Qt::Key_A: case Qt::Key_B: case Qt::Key_C: case Qt::Key_D: // call a function that

Efficient way to move QGraphicItems inside QGraphicsScene

时间秒杀一切 提交于 2019-12-24 14:33:36
问题 I am developing a video player using pyqt5. I am using QGraphicsVideoItem inside a scene. On top of this videoitem, I also need to have some polygons that move around the scene on each new frame. They track things in the video. Ideally I wan't to get them to move with 30 fps. I did a test run, where I moved 1 polygon by 1 pixel at a speed of 30 fps. I did this with the setPos() function in the QGraphicsPolygonItem. This works, but it is very wonky and each time the polygon you can see it

Removing Qpixmap from QGraphicsScene

好久不见. 提交于 2019-12-24 10:11:03
问题 I enconutered a problem, when dealing with QGraphicsScene and QPixmap. I am sequentially displaying frames, captured by the camera. QTimer object is calling updateSingleView() function every 100ms. That is my inner function: void CCIGui::updateSingleView() { unsigned char *const img = PGRSystem->SnapShot(); QImage Img(img, 1024, 768, QImage::Format_RGB888); scenes.at(0)->removeItem(scenes.at(0)->items().at(0)); scenes.at(0)->addPixmap(QPixmap::fromImage(Img)); ui_camViews.at(0).graphicsView-

QGraphicsView/QGraphicsScene: How to fix an item's X or Y coordinate during rotation?

☆樱花仙子☆ 提交于 2019-12-24 07:38:45
问题 I have about 150 QGraphicsLineItems in a QGraphicsScene, and I want to "rotate" them, but have the rotation not affect their X coordinate. In other words, they would move vertically according to a given rotation angle, but they wouldn't actually rotate or move horizontally. The reason I'd like to do this is that there are several other items in an adjacent QGraphicsScene/View that are rotated normally, and I want the items in this new scene/view to match the displayed height of the normally