qgraphicsscene

Fit QGraphisItem in view

我们两清 提交于 2020-06-09 02:56:11
问题 Is a method to fit any image in view (that I import in QPixmap) and keep aspect ratio>. I try many solution but non of those works. Also I don't not sure what I need to fit? QGraphicsScene in QGraphicsView? Or QPixmap in QGraphicsView? from PyQt5 import QtCore, QtGui, QtWidgets class GraphicsView(QtWidgets.QGraphicsView): def __init__(self, parent=None): super(GraphicsView, self).__init__(parent) scene = QtWidgets.QGraphicsScene() self.setScene(scene) if __name__ == "__main__": import sys app

Join QGraphicsItem and QPainter in same GraphicsScene

可紊 提交于 2020-05-17 06:14:28
问题 I am currently building an interactive canvas using PyQt5 and Graphicscene, so far modifying the codes found on those posts: PySide Node Graph connect items How to draw a line from mouse to a point in PyQt5? I have made two separates examples of what I would like , but so far I have not been able to merge the two into a single code. The first code I inserts a node and corresponding edge in the position clicked on the screen. Begins and ends with a double click of the left button of the mouse.

Toggle QPen for selected items after QGraphicsScene selection change

我们两清 提交于 2020-03-19 07:55:34
问题 How can I toggle the QPen color for the selected graphicsview items? Ideally I would like to handle this color change in the graphicsview or graphics scene objects rather than directly handling it in the main windows selection event. Any help is appreciated. Currently it will turn the pen color white when the object is selected. I'm not sure how to turn it back avoiding looping through all objects. Is there a way i could add a function in the MyGraphicsView class itself that would handle the

Alternatives to static and global in C++?

 ̄綄美尐妖づ 提交于 2020-01-14 07:11:11
问题 I have a class instance that needs to be accessed by some other classes. It would be quite cumbersome to pass the instance always down the construction chain. I tried to avoid global variable, since people tend to advise against this. I thought I declare this instance a static member of a class and then include this class in order to access the instance but this does not work either error: calling a private constructor of class 'Foo' To specify the problem further in the context of the

pyqtgraph: how to drag a a plot item

柔情痞子 提交于 2020-01-14 03:52:07
问题 Currently trying to plot a scatter plot in pyqtgraph and trying to drag the plot items but unable to find the approach. Already looked at GraphicsScene sigMouseClicked, sigMouseMoved events. Any suggestions welcome. Let me know in case any further details are required from my side. Sample code which I am using: import pyqtgraph as pg import numpy as np w = pg.GraphicsWindow() w.show() x = [2,4,5,6,8]; y = [2,4,6,8,10]; pl = pg.PlotItem() pl.plot(x, y, symbol='o') w.addItem(pl) 回答1: Have a

QGraphicsPathItem hoverEvents - suppress hover on area formed by the path

一世执手 提交于 2020-01-06 03:17:51
问题 https://www.dropbox.com/s/phven3rriv36893/graphicsview-pathitem.png?dl=0 I wonder if there's a way to make my QGraphicsPathItem respond to mouseHoverEvents to the actual curve instead of the whole orange area as seen in the docs. https://www.dropbox.com/s/7m8w34nitp34sgf/pipes.png?dl=0 In my application I'm not seeing the area that actually forms the path and therefor I only want a hoverEnterEvent when the bezier curve is hovered (and a hoverLeaveEvent when the bezier is left of, course). Is

QGraphicsView fitInView margins

别说谁变了你拦得住时间么 提交于 2020-01-03 15:13:12
问题 Why this: graphics_view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio); doesn’t work as expected ? It isn't fitting the scene rect correctly, showing margins around it. 回答1: The cause is this: https://bugreports.qt.io/browse/QTBUG-42331 - please vote on it on the qt bug tracker to up its priority. In short, fitInView has hardcoded margins and this can cause all kinds of havoc - the least of which is that now you lose a few pixels of display area and might also force unnecessary rescaling

Saving a QGraphicsScene to Svg changes scaling

夙愿已清 提交于 2020-01-03 03:13:11
问题 I need to save the items from my QGraphicsScene to an svg, and be able to load that svg back on the scene. I can do it... But each time the canvas is saved to svg, upon load the items are somewhat bigger (and repeatedly saving and loading the same svg causes it to grow). I can't find the cause. I am attaching a sample code - and the result. test1.pro QT += gui svg greaterThan(QT_MAJOR_VERSION, 4): QT += widgets core TARGET = test1 TEMPLATE = app SOURCES += \ svggenerator.cpp svggenerator.cpp

Prevent QGraphicsItem from moving outside of QGraphicsScene

为君一笑 提交于 2020-01-01 08:33:55
问题 I have a scene which has fixed dimensions from (0;0) to (481;270): scene->setSceneRect(0, 0, 481, 270); Inside of it, I have a custom GraphicsItem and I can move it thanks to the flag ItemisMovable , but I would like it to stay within the Scene; I actually mean I don't want it to have coordinates neither under (0;0) nor over (481;270). I tried several solutions like overriding QGraphicsItem::itemChange() or even QGraphicsItem::mouseMoveEvent() but I still cannot manage to reach what I want to

QGraphicsSimpleTextItem “invalid use of incomplete type”

寵の児 提交于 2019-12-31 07:16:05
问题 My code is as follows: pointerwidget.h QGraphicsSimpleTextItem *text; pointerwidget.cpp void PointerWidget::placeNumbers(float spacing, int currentTickNumber) { float label = spacing/scaleFactor; text = scene->addSimpleText(QString::number(label),QFont("Comic Sans MS", 12, QFont::Bold)); text->setPos(currentTickNumber*spacing,30); } Everywhere that i read says to use setPos(x,y) to position the text item. This is a function of QGraphicsItem. I get the error of "invalid use of incomplete type