Skip to content
  • 0 Votes
    3 Posts
    299 Views
    O

    @jsulm
    Indeed! Thank you for your reply.

  • 0 Votes
    9 Posts
    572 Views
    O

    @JonB

    You are absolutely right! I was confused between the QGraphicsView and the QGraphicsScene. I just realised that when I was playing with my POC.

    Actually, what change the size of the QGraphicsScene is done in another part of my code and is called later. If I recalculate the sceneRect according to my needs and call setSceneRect(), when my window is resized, everything works as expected.

    Sorry for the inconvenience.

  • 0 Votes
    10 Posts
    912 Views
    C

    Hi,

    See if this provides some explanation (read the comments as well):

    StackOverflow: Qt6 QLabel / QPixmap excessive memory usage

  • 0 Votes
    6 Posts
    460 Views
    NarutoblazeN

    @Pl45m4 @mpergand thanks for you time it worked perfectly for me

  • 0 Votes
    2 Posts
    191 Views
    JonBJ

    @misscoffee
    So just set the size of the view and/or scene to the full size of the screen/desktop. You can also use void QWidget::showFullScreen() (see the warnings there).

    Be aware that widgets/windows have borders, and a title bar unless you specify otherwise, so the view/scene may not occupy every pixel of the screen, unless you take action, if that matters to you. IIRC, graphics scene/view places coordinate (0,0) in the center with x,y increasing right/up. You can use setSceneRect() to alter this.

  • 0 Votes
    5 Posts
    654 Views
    S

    @JonB thanks for googling :) . I have seen some more example. In case of GraphicsView fill transparent on scene did not help. I am pretty sure there is some way to do it, need to google more

  • 0 Votes
    6 Posts
    1k Views
    W

    @JonB I moved my code into QGraphicsView::drawBackground() as you recommended, it works nicely. Thanks a lot!

  • 0 Votes
    5 Posts
    491 Views
    N

    @wrosecrans
    I know that I need them. But don‘t know how to apply them on the scene and keep everything thats on that. I thought that the rect itself has the points in it using the render function of the QGraphicsScene is enough.

    What I do: I set the DragMode of the QGraphicsView to rubberband so the user can select some part pf the scene by simply dragging. The returned rect is now sent to the view to get the underlying image of the scene.

  • 0 Votes
    7 Posts
    1k Views
    SGaistS

    Animation, composition, overlaying and whatever comes to your imagination.

    That said, if you are really only showing one single image and nothing more then, indeed, a QLabel is enough.

  • 0 Votes
    6 Posts
    2k Views
    SGaistS

    Depending on your end goal, you might want to consider using a library like OpenCV to do the zooming part and Qt to display the result.

  • 0 Votes
    2 Posts
    563 Views
    JonBJ

    @Dariusz
    I admit I have not tried it, but it would seem very strange to me if "Sadly at that point QGraphicsView decides to not draw item & my line dissapears.". I would expect it merely to clip whatever there is to the visible view area; if it omitted it completely QGraphicsView would surely be unusable.

    Say if i Have a rect item at 500/500, and inside that item I have a path that stretches all the way to 0,0.

    What do you mean by this? Are you putting further line items on top of a rect item as children? The vital thing is that you must not draw outside a QGraphicsItem::boundingRect() and QGraphicsItem::childrenBoundingRect(). If you do, the view will misdraw. You can override QGraphicsItem::boundingRect() for your items if you need to. Is this perhaps your situation?

  • 0 Votes
    4 Posts
    809 Views
    Pl45m4P

    @HappyVisualizer

    Since your view is in a layout... have you tried to set the layout margin to 0?

  • 0 Votes
    8 Posts
    1k Views
    SGaistS

    Great !

    Since you have it working now, please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so that other forum users may know a solution has been found :-)

  • 0 Votes
    2 Posts
    406 Views
    D

    For any1 wondering, its more or less >
    item->setPos(mNodeViewPtr->mapToScene(mNodeViewPtr->mapFromGlobal(QCursor::pos())));
    you can most likely do mNodeViewPtr->viewport()->mapFromGlobal() for more precision I think but I didn't test it.

  • 0 Votes
    2 Posts
    409 Views
    JoeCFDJ

    @RobotMaker said in Svg Rendering Perspective Transform on QGraphicsView Viewport:

    Some code will be helpful. And how you update it?

    try to call this after your change to update it. I use it to toggle svg pics display.
    update(const QRectF &) ==>update( boundingRect() ); I assume you overrides boundingRect();

  • 0 Votes
    8 Posts
    953 Views
    Pl45m4P

    @sticky-thermos said in Receive Drag/Drop events for items in QGraphicsScene:

    void ChessBoard::mouseMoveEvent(QMouseEvent *event) {
    std::cout << FUNCTION << std::endl;
    QGraphicsView::mousePressEvent(event);
    QDrag *drag = new QDrag(this);
    QMimeData *mime = new QMimeData; // this is necessary even if nothing is set in the mime data
    drag->setMimeData(mime);
    drag->exec();
    }

    Looks good, but I would add a check to differenciate whether your mouseButton is down. Otherwise you are creating a lot of drags from just moving your mouse around on your chessBoard.

    Also, you are passing the ChessBoard::mouseMoveEvent(QMouseEvent *event) to QGraphicsView::mousePressEvent(event).
    QGraphicsView::mouseMoveEvent would be more fitting :)

  • 0 Votes
    5 Posts
    593 Views
    D

    @Pl45m4 no but I don't know how to do that sizeHint() can return the right size in a layout.and I have a valid parent.

  • 0 Votes
    8 Posts
    621 Views
    D

    @SGaist ok I see, but I still can't get the size after layout(this return QtCore.QSize())

    self.graphicsView_3.adjustSize() print(self.graphicsView_3.size())

    full code

    from PyQt5 import QtCore, QtGui, QtWidgets from PhotoViewer import PhotoViewer class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.gridLayout = QtWidgets.QGridLayout(self.centralwidget) self.gridLayout.setObjectName("gridLayout") self.graphicsView_2 = QtWidgets.QGraphicsView(self.centralwidget) self.graphicsView_2.setObjectName("graphicsView_2") self.gridLayout.addWidget(self.graphicsView_2, 2, 0, 1, 1) self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget) self.graphicsView.setObjectName("graphicsView") self.gridLayout.addWidget(self.graphicsView, 1, 0, 1, 1) self.graphicsView_3 = PhotoViewer(self.centralwidget) self.graphicsView_3.adjustSize() print(self.graphicsView_3.size()) self.graphicsView_3.setObjectName("graphicsView_3") self.gridLayout.addWidget(self.graphicsView_3, 1, 1, 1, 1) self.graphicsView_4 = QtWidgets.QGraphicsView(self.centralwidget) self.graphicsView_4.setObjectName("graphicsView_4") self.gridLayout.addWidget(self.graphicsView_4, 2, 1, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 25)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow")) if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())
  • 0 Votes
    9 Posts
    1k Views
    jeremy_kJ

    @canol said in Removing a QGraphicsProxyWidget from QGraphicsScene crashes the app, but only when using a button on a toolbar:

    Hello, I have a medium sized app which had some random crashing problems. The crashes don't print any error messages. After a long investigation, getting rid of a lot of code, now I have a minimal example.

    For problems that don't appear to produce any usable output, turning on all QLoggingCategory categories can help. QT_LOGGING_RULES="*.*=true" python test.py should flood the console with information about what Qt is doing prior to the crash.

    In addition, installing a QObject::eventFilter() on the widget or QApplication can provide insight into how far input processing proceeded.

    class Filter(QObject): def __init__(self, target, *args, **kwargs): super().__init__(*args, **kwargs) target.installEventFilter(self) def eventFilter(self, target, event): print("Attempting to deliver {} to {}".format(event.type(), target)) return super().eventFilter(target, event) app = QtWidgets.QApplication([]) filter = Filter(app)

    The app has a QGraphicsView, and I add and remove QWidgets dynamically on the graphics view. The widgets have a toolbar, and the toolbar had a close button on it, which removes and deletes the widget from QGraphicsView. The crashes would randomly happen when I used this close button.

    Here is a complete example (it is a PySide2 program, I haven't tried it with C++):

    Porting the example to PyQt5 had crashes for the same input, on every attempt. Maybe PyQt is more aggressive in object reclamation than PySide.

    My questions are:

    **1) Why does it crash when I trigger the action using mouse click on the button?

    The issue appears to be a deletion of the recipient object while there are events for it remaining in the queue. As mentioned in the documentation for QObject::~QObject(), this is a problem.

    In C++, QObject::deleteLater() provides a convenient solution. Unfortunately, PySide and PyQt interfere by deleting the object when the last python reference is removed.

    Why does it NOT crash, when I use the keyboard shortcut for the action?**

    Different triggering mechanisms lead to a different sequence of events. If the last event triggers the action, deleting the object is fine. If there's a mouse release or a paint event after, deletion in the slot connected to the action is unsafe.

    The example above uses a QPushButton, instead of a QToolBar+QAction, and it does not crash. So another question:

    3) Why does it not crash when I use QPushButton instead of QToolBar+QAction?

    As with #2, the events delivered are probably different.

    This example won't crash. I guess waiting for the control to return to event loop before removing the item helps. So my final question is:

    4) Why does using QTimer.singleShot() helps here?

    Using QTimer.singleShot() schedules the slot for the next iteration of the event loop, after the currently pending events have been processed. The same thing can be accomplished using a queued connection for the action's slot instead of a 0-timer.

  • 0 Votes
    18 Posts
    2k Views
    S

    @mrjj . Thanks a ton for your help. Its working perfectly.