qgraphicsview

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

Click event for QGraphicsView Qt

被刻印的时光 ゝ 提交于 2019-12-23 18:33:05
问题 I have made a GUI in Qt that is basically a widget with a QGraphicsView on it i have a function: void GUI::mousePressEvent(QMouseEvent *event) { if(event->button() == Qt::LeftButton) { QPointF mousePoint = ui->graphicsView->mapToScene(event->pos()); qDebug() << mousePoint; } } which links to a public slot: void mousePressEvent(QMouseEvent *event); this shows me on the console the x,y coordinate of where i have clicked, however currently this is working on the entire widget and i ideally would

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

Handling MouseEvents in Qt c++

吃可爱长大的小学妹 提交于 2019-12-23 13:24:08
问题 Sorry for my beginner's question... What is the easiest way to define procedures, which are executed when MousePressEvent or MouseReleaseEvent occurs? For now I am defining my own class (MyGraphicsView class), which inherits QGraphicsView and I am reimplementing mouse events (which are virtual functions). It works fine but is there any way to solve this problem without a need to define a new class? Can I connect Events with Slots somehow? Thanks for your help. 回答1: This thread on the Qt

Events with QGraphicsItemGroup

孤人 提交于 2019-12-23 07:37:06
问题 In my application I want to use QGraphicsItemGroup for grouping items into one item. I played with it a little and not sure using it because when I want to catch events, events are merged together but I want to handle specific event with specific child. How can I achieve this? 回答1: You need to call QGraphicsItemGroup::setHandlesChildEvents(false) . This stops the QGraphicsItemGroup trying to handle the event, and lets the child QGraphicsItem s handle them instead. 回答2: I think that's the

Why is a rectangle partly outside of view drawn as a triangle?

佐手、 提交于 2019-12-23 06:56:09
问题 I use the Python-Qt bindings from PySide and I want to draw a scene with amongst others a rectangle and the rectangle is not fully visible because the view should only show a part of the scene where the rectangle is not fully contained. Here is a minimal example: from PySide.QtGui import * app = QApplication([]) scene = QGraphicsScene() scene.addRect(0, 0, 100, 100) view = QGraphicsView(scene) view.setSceneRect(-60, 20, 100, 100) view.show() app.exec_() I expect to see the lower part of a

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-

how to create a pie chart with pyqt in python

泄露秘密 提交于 2019-12-22 14:14:46
问题 Trying to create a pie chart shape but for some reason I can't get it to join together correctly. When I run my code It creates a lot of segments on top of each other. Here is my code: from PyQt4.QtCore import * from PyQt4.QtGui import * import sys, random app = QApplication(sys.argv) scene = QGraphicsScene() families = [1,2,3,4,5,6,7] total = 0 colours = [] set_angle = 0 count1 = 0 total = sum(families) for count in range(len(families)): number = [] for count in range(3): number.append

How to unit test qt graphics view widgets/items

我的未来我决定 提交于 2019-12-22 04:22:28
问题 I have an application that makes extensive use of the graphicsview architecture in Qt4 and I would like to start automated testing of the ui components, but I cannot find any resources related to what I should be testing or how to test qgraphicsview/qgraphicswidget based classes? 回答1: I've been running into problems trying to unit test QGraphicsView. My biggest problem was that QTest::mousePressEvent(view, Qt::LeftButton, 0); results in Mouse event "MousePress" not accepted by receiving

How can i make 2-layers in QGraphicsView?

不想你离开。 提交于 2019-12-20 05:28:05
问题 In the program below, load the background image and paint it on it. But, I got a problem. In this program, when i use 'eraser' tool, the background image is erased too! Actually, I just want to erase what i painted, except background image. And then, I'd like to save only the painted ones(layer) as an image. In this case, What should i do? import sys from PyQt5.QtCore import * from PyQt5.QtCore import Qt from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtWidgets import