qgraphicsscene

Qt: How do I notify changing mouse coordinates to parent object

混江龙づ霸主 提交于 2019-12-12 06:15:35
问题 I have a little problem with the Qt class QGraphicsScene : To detect the current mouse coordinates I made a new class QGraphicsScenePlus with QGraphicsScene as the base class. I have already redefined the slot function mouseMoveEvent(QGraphicsSceneMouseEvent* event) and the received coordinates seem to be correct. Now I want to notify the parent QMainWindow class, where the QGraphicsScenePlus object is stored, whenever the mouse coordinates change. What is the best way to do this? I already

setpixel of QGraphicsScene in Qt

南楼画角 提交于 2019-12-12 03:19:41
问题 It's simple to draw line or ellipse just by using scene.addellipse(), etc. QGraphicsScene scene(0,0,800,600); QGraphicsView view(&scene); scene.addText("Hello, world!"); QPen pen(Qt::green); scene.addLine(0,0,200,200,pen); scene.addEllipse(400,300,100,100,pen); view.show(); now what should i do to set some pixel color? may i use a widget like qimage? by the way performance is an issue for me.thanks 回答1: I think that performing pixel manipulation on a QImage would slow down your application

Rendering a large QGraphicsScene on a QImage clips it off

雨燕双飞 提交于 2019-12-12 01:59:12
问题 I am creating some images rendering the contents of a QGraphicsScene . My project requirement is that it should handle a canvas size of 10 ft by 8 inches. On screen, and scene size, that is 8640 x 576 pixels. I can render it fine. The thing is, the output images need to have 300 resolution. That means, the rendered image will have a width of 36000, which is over 2^15 - 1 = 32767 pixels..... The output is clipped - in the code below, I would get a QImage of correct expected size (36000) but

QT GraphicScene - Text label collission

六月ゝ 毕业季﹏ 提交于 2019-12-12 01:45:43
问题 I want to stop labels colliding within my Scene and as a result used this code to check for a collision:- QGraphicsTextItem *textLabel = new QGraphicsTextItem; .... addItem(textLabel); //check for collision QList<QGraphicsItem*> items = this->items(textLabel>boundingRect(),Qt::IntersectsItemBoundingRect); I never get any items in the list, yet on screen I can see the collisions. Am I reading the documentation incorrectly? 回答1: You're checking if any items are colliding with the label's

Why do my my line widths looks different in a QGraphicsScene with the same QPen width?

 ̄綄美尐妖づ 提交于 2019-12-11 13:12:29
问题 I use a QPainter to draw my widget with this code: QPen pen(Qt::black, 0.6, Qt::SolidLine); QPainter painter(this); painter.setPen(pen); // vertical painter.drawLine(startX,0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); painter.drawLine((startX += grid),0,startX,50); // horizontal pen.setWidth(0.7); painter.setPen(pen); painter.drawLine

Qgraphicsscene troubles to get scenePos() inside a function

我的梦境 提交于 2019-12-11 08:26:27
问题 I have subclassed a qgraphicsscene and trying to get the mouse coords inside a "normal" function. I only get it working on "mouse involved" function. Sorry I'm amateur programmer. For exmample here scenePos() works: void mousePressEvent(QGraphicsSceneMouseEvent *event) { // qDebug() << "Custom scene clicked."; if(event->modifiers() == Qt::ControlModifier) { if(event->button() == Qt::LeftButton) { QPointF pos = {event->scenePos().x(), 70}; addChordnueve(pos); // crea 1 item at mouse x e y = 70

How to add item in a QGraphicsScene?

南楼画角 提交于 2019-12-11 06:54:21
问题 I am trying to add some custom QGraphicsItems in a QGraphicsScene on mouse click and at mouse cursor coordinates. But the items are not added at the same coordinates as the mouse cursor's. renderArea::renderArea(QWidget *parent): QGraphicsView(parent) { scene = new QGraphicsScene(this); scene->setItemIndexMethod(QGraphicsScene::NoIndex); scene->setSceneRect(0, 0, 850, 480); setScene(scene); setCacheMode(CacheBackground); setViewportUpdateMode(BoundingRectViewportUpdate); setRenderHint

PyQt. How to block clear selection on mouse right click?

て烟熏妆下的殇ゞ 提交于 2019-12-11 05:28:24
问题 I have a QGraphicsScene and many selectable items. But when I click the right mouse button - deselects all objects. I want show menu and edit selected objects but have automatic deselect any time when right click at mouse... Perhaps the problem is that I have included an rubber selection. selection of objects in the end is how the right and the left mouse button when I pull the frame and therefore is reset at single time you press the right button... How to leave objects highlighted when you

For QGraphicsScene using setZValue on a QGraphicsItem causes major slowdown

旧时模样 提交于 2019-12-11 05:21:56
问题 I'm using Qt (Mac, version 4.7) to rendering a rather large scene (map data from Open Street Maps) with QGraphicsView and QGraphicsScene. Everything works great until I try to set the Z value for the items in the scene. I've tried two separate approaches to do this. In one, I just do: QGraphicsPathItem *item = scene->addPath(path, pen); item->setZValue(z); and the other I create my own QGraphicsItem subclass, but get the exact same problem. The cause of the slow down appears to be on the Qt

Moving QGraphicsItem by mouse in a QGraphicsScene

谁都会走 提交于 2019-12-11 03:36:09
问题 I have a QGraphicsScene and its associated QGraphicsView . I let the user create some shapes in the form of derived QGraphicsItem s into that scene. I also want them to be movable by mouse. Clicking one or more items select them, and moving them around while the mouse button is pressed works. I inherited QGraphicsView to do this, and overrided mousePressedEvent , mouseReleasedEvent & mouseMoveEvent to achieve this. When the user clicks, I am basically testing if an item (accessed through