qgraphicsview

QGraphicsView and QGraphicsItem: don´t scale item when scaling the view rect

一个人想着一个人 提交于 2019-12-03 09:37:18
问题 I am using Qt´s QGraphicsView - and QGraphicsItem -subclasses. is there a way to not scale the graphical representation of the item in the view when the view rectangle is changed, e.g. when zooming in. The default behavior is that my items scale in relation to my view rectangle. I would like to visualize 2d points which should be represented by a thin rectangle which should not scale when zooming in the view. See a typical 3d modelling software for reference where vertex points are always

How to select multiple items without pressing Ctrl key within QGraphicsScene?

≯℡__Kan透↙ 提交于 2019-12-03 03:52:53
In Qt's QGraphicsScene , if I wanna one item, just click it, and click another selectable item will make the selected item to be unselected. If I want to select multiple items, I'd use Ctrl-key. But this maybe not convenient for some cases, then how to select multiple items without pressing Ctrl-key within QGraphicsScene ? You want to change the default behavior of QGraphicsScene , so you have to create your own scene class, inheriting QGraphicsScene . In your class, you'll have to reimplement at least mousePressEvent and handle the item selection yourself. Here is how you could do it (the

QRubberBand move on QGraphicsView after resizing

可紊 提交于 2019-12-02 07:02:47
I have the same problem from this topic: QRubberBand move when I resize window , after a few try I realized that solution from this topic doesn't apply on QGraphics View. Why my selection move, arout QgraphicsView when I resize window. import sys from PyQt5 import QtCore, QtGui, QtWidgets # from PyQt4 import QtCore, QtWidgets class ResizableRubberBand(QtWidgets.QGraphicsView): def __init__(self, parent=None): super(ResizableRubberBand, self).__init__(parent) self.draggable = False self.mousePressPos = None self.mouseMovePos = None self._band = QtWidgets.QRubberBand(QtWidgets.QRubberBand

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

倖福魔咒の 提交于 2019-12-02 03:47:00
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 = QPushButton('Crop') self.b3 = QPushButton('Clear') self.view = GraphicsView() h_box = QHBoxLayout() v

Fixed QGraphicsItem position, without changing behaviour of other QGraphicsItems in scene

时光怂恿深爱的人放手 提交于 2019-12-02 01:05:03
问题 This question is related to: Forcing QGraphicsItem To Stay Put I'd like to have a QGraphicsItem on a fixed location when moving around in the scene. The suggested solution is to override the void paintEvent(QPaintEvent*) of the sub-classed QGraphicsView . void MyGraphicsView::paintEvent(QPaintEvent*) { QPointF scenePos = mapToScene(0,0); // map viewport's top-left corner to scene myItem->setPos(scenePos); } However, the problem is that I want everything else in the scene to stay intact, i.e.

Forcing QGraphicsItem To Stay Put [duplicate]

眉间皱痕 提交于 2019-12-01 15:59:06
问题 This question already has an answer here : Draw an item in a static location relative to the QGraphicsView (1 answer) Closed 6 years ago . I have a QGraphicsScene that is filled with QGraphicsItems , and the user is able to pan and zoom around to inspect all of the various QGraphicsItems . However, I would like to have a QGraphicsTextItem label that always stays put at the top left of the screen. Ignoring the zooms is easy, as I can just setFlags(QGraphicsItem::ItemIgnoresTransformations) ,

Removing dotted rectangle on selected item

ぐ巨炮叔叔 提交于 2019-12-01 12:50:23
I have been trying to learn a bit more about the QGraphicsView widget by taking a look at this example here: Toggle QPen for selected items after QGraphicsScene selection change I found this fairly helpful, however i noticed that upon selection there is marquee thing that pops up when an item is selected. I was looking at ways to get rid of this, and it seems like there is a consistent answer to this in C++ which I see as an example here: https://www.qtcentre.org/threads/39659-About-QGraphicsItem-question But i am very confused as to how to translate this into pyqt, so I was wondering if

MousePressEvent, position offset in QGraphicsView

核能气质少年 提交于 2019-12-01 04:52:49
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=None): painter.fillRect(self.rectF, QtCore.Qt.red) class graphicsScene (QtGui.QGraphicsScene): def __init_

Fixed size QGraphicsItems in multiple views?

徘徊边缘 提交于 2019-12-01 03:57:08
问题 I'm visualizing a graph using Qt's graphics view framework. It looks something like this: Now, I want the size of the vertices, which I'm drawing as small filled circles, to remain constant relative to the zooming of the view. At the moment I'm accomplishing this by not having my vertices as items in the scene, but instead drawing them in the view's drawForeground(...) function, like this: void View::drawForeground(QPainter *painter, const QRectF& rect) { painter->setMatrixEnabled(false);

How to use the QGraphicsView's translate() function?

喜欢而已 提交于 2019-12-01 03:19:50
here i have a scene and a associated view ,then i hava a position in the scene coordinates.I want to set the center of the viewport with the position.How can i do it? I try to use the translate() function but it didn't work? view->translate(10, 10); The viewport should move with the delta x 10, and delta y 10, but it didn't work! Center As said Frank Osterfeld , to center your viewport at a given position, you can simply use the function centerOn . Translate But to translate your viewport, it exists another way that consists to change your scrollbars position : // Your graphics view