qgraphicsscene

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

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

Why is the selection border of a QGraphicsWidget not visible in QGraphicsScene?

为君一笑 提交于 2019-12-24 01:29:07
问题 I have added a widget to a graphic scene (QGraphicScene) through a QGraphicsProxyWidget . The problem is that when I select the item it's selected, but the selection border is not visible. Here is the code: QDial *dial= new QDial(); // Widget dial->setGeometry(3,3,100,100);// setting offset for graphicswidget and widget QGraphicsWidget *ParentWidget = new QGraphicsWidget();// created to move and select on scene ParentWidget->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem:

QGraphicsScene::clear doesn't change sceneRect

大城市里の小女人 提交于 2019-12-24 00:58:25
问题 I have a QGraphicsScene "scene" and QGraphicsView "graphicsView". I have a drawing method. When I need redraw all the graphics, I call this method. Everything is OK. But I realized that scene->clear() doesn't change the sceneRect. Also I tried: graphicsView->items().clear(); scene->clear(); graphicsView->viewport()->update(); After that, if I get the sceneRect by QRectF bound = scene->sceneRect(); qDebug() << bound.width(); qDebug() << bound.height(); I expect the bound.width and bound.height

Qt: Line connects 2 separate drawings

倖福魔咒の 提交于 2019-12-23 15:43:33
问题 i want to draw different arbitrary figures. Drawing starts when the mouse is clicked in the graphicsview and ends when stop clicking the mouse. However, when starting at a different point in the graphics view to make a new drawing, or to continue on the previous drawing, a line is drawn from the last mouse coordinate of the first drawing, to the first coordinate of the second drawing. The drawings do not necessarily need to be different drawings, but can also just be adjustments to the

Update Scene from Thread?

末鹿安然 提交于 2019-12-23 05:14:04
问题 I need to update a QGraphicsView with a QGraphicsScene from a thread. Below is some pseudo'ish code example of what I am doing which is causing me issues (runtime errors). What am I doing wrong, and how should I be doing it? Main App: void Main::startThread() { view = new QGraphicsView(...); thread = new MyThread(...); connect(thread, SIGNAL(doSceneUpdate(QGraphicsScene*)), this, SLOT(updateScene(QGraphicsScene*))); thread->start(); } void Main::updateScene(QGraphicsScene *scene) { view-